Messages in this thread | | | Subject | Re: Network socket disconnect unreliable | Date | Sat, 19 Feb 2000 00:39:03 +0000 (GMT) | From | Alan Cox <> |
| |
> When a network socket disconnects, this fact can't presently be > reliably detected when using select. The exception bit is set, but this
It can be
> So, how am I supposed to know if the socket was disconnected? > There are of course hacks. I can just count the number of times > that this thing looped without finding anything to do and then > exit if it's obvious that it's hung.
If a socket is closed by the other end then it goes EOF for read once all the data has been read. This is a portable property of sockets, its true of BSD and its defined by posix 1003.1g drafts. So you do
if(FD_ISSET(fd, &read_mask)) { int len=read(fd, buffer, bufsize); if(len==0) { /* EOF - closed */ } if(len<0) { if(errno==EAGAIN) { /* woken by something else */ /* Not needed in theory but is for porting */ } else { /* it broke */ } } }
Alan
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |