• Advertisement
Sign in to follow this  

one thread waiting, another thread closesocket

This topic is 3225 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've a quick question: if one thread is waiting in a select or epoll when another thread calls closesocket, will the select or epoll returns an error immediately?

Share this post


Link to post
Share on other sites
Advertisement
Consult your socket library documentation.

In general, yes, it's a common way to cancel pending socket operations. For example, in the .NET Framework this is the only way to abort a BeginReceive() call on a socket.

On Windows, you can avoid the scenario with WaitForMultipleObjects(): Just let the thread wait on the socket and an event at the same time. If you need to close the socket, wake up the thread by signaling the event, wait for the thread to exit and then close the socket.

There's probably a similar option on Linux. I don't know if there's a portable path to both, though.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement