Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to cancel a blocking socket call ?

Status
Not open for further replies.

RbgoWeb

Programmer
Apr 10, 2002
91
NL
When using accept() on a blocking socket (possibly in a separate thread), the call will not return untill a client connects with connect().

Is there a way to interrupt this blocking accept() call?
 
Try closesocket() on this socket (from the other thread, of course). Some years ago I have used this brutal approach: it was OK...
 
Still a question:
I have a datablock in the main thread in which the listening_socket is declared and setup.
I pass this datablock to the thread with the accept() blocking call that uses the listening_socket.
Do you think I need to use EnterCriticalSection() before I call closesocket(listening_socket)?
 
I think the answer: no need. Socket handles in your program refers to internal Winsock kitchen: let Winsocket deals with its sockets...
But you need to invent (or use) some kind of thread synchronization mechanics, of course (to control all your threads execution).
It seems the worst case - accept() in socket thread returns any error code...
Please, carefully test my suggestion before use. It seems it's not so hard test case emulate this forced disconnection. Now I can't do it, sorry...
Good luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top