Quick Winsock question
When shutting down my client sockets in my server app, I want to read whatever is left in the receive buffer.
So I did this, after shutdown(), but before closesocket():
while(recv(blah blah blah) > 0) // while we have stuff left
{
// store stuff in a buffer or just junk it
}
However, this brings up a strange problem. Whenever a client is disconnected by the server, it seems to be hanging in the loop until the client''s end of the socket closes, which is obviously not what I want.
Anyone have any ideas on what else I need to be doing? Again, to summarize, I want to shutdown the socket, grab anything left in the receive buffer, and then close the socket - this is for when a client times out or the server shuts down.
Help appreciated.
-GenmaC
May 25, 2002 06:02 PM
A blocking recv() won''t return until it has some data to return. So your problem is most likely that there is no data in the buffer, so recv() doesn''t return until the client disconnects (which will cause recv() to return with 0). Either use a non-blocking recv() or use select to see if there is any data to be read first.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement