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

前端 未结 3 1491
被撕碎了的回忆
被撕碎了的回忆 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 11:09

    If your program has other things to do besides working with socket I/O, you should not block in the first place.

    You claim your thread must wait, but that's just a reflection of your program's current design. You should redesign it so it works with some form of non-blocking sockets. Every networking problem can be addressed using non-blocking sockets.

    Since you're using Winsock, you have many alternatives here, not just select(). select() is a good choice only if your application must run on many platforms and you are unable to use the superior (but mutually incompatible) alternatives available on every modern platform.

提交回复
热议问题