Advertisement

Detecting when a client socket has closed?

Started by March 09, 2004 08:45 AM
0 comments, last by Promit 20 years, 11 months ago
I''ve succesfully coded up a system that uses select() to check for data on a socket and then recv() on that socket. Problem is, data isn''t what select() checks for; it''s "readability". A closed socket is defined as readable, since a call to recv on that socket is guaranteed not to block (it''ll return immediately with 0). So is there any special function to check for a closed socket, or a flag in select()? Or do I just add a check for when recv returns 0? Are there any other conditions where recv can return 0 but the socket hasn''t closed?
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
If you are using winsock and synchronous sockets, you should use WSAAsyncSelect with FD_CLOSE. Otherwise checking for 0 or error is enough.

This topic is closed to new replies.

Advertisement