View Single Post
Old 04-03-2006, 09:56 AM   #3 (permalink)
kyoryu
Registered User
 
Join Date: Apr 2003
Posts: 34
kyoryu is on a distinguished road
What are you using to check the socket for available data/receive the data?

EDIT:

Since your other thread asked about poll(), I'm going to assume you're poll()ing your sockets.

If that's the case, the way to determine if you have a disconnected socket is to see if poll() returns either POLL_READ or POLL_HUP, and a subsequent read() from the socket returns 0 bytes.

The status of POLL_HUP and POLL_READ is *not* consistent between OS's, and is somewhat undefined. What either will tell you, however, is that if you read from the socket you won't block. On an open socket, this means that there's data available.

Doing a read from that socket, once you know it won't block, and getting zero bytes then tells you that the socket is closed.
kyoryu is offline   Reply With Quote