[c++winsock2.0]How to abort winsock blocking call?

前端 未结 3 1506
被撕碎了的回忆
被撕碎了的回忆 2020-12-22 10:04

I use Winsock 2 in C++, and wonder how to make my server stop reading from the client connection. The reading thread gets blocked in recv() and I have no idea h

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-22 10:55

    To abort the blocking call to recv(), you can close the socket with closesocket() from another thread. Even if it's a bit ugly, it should work.

    You can try to shutdown() the socket too (I never tested that).

提交回复
热议问题