lkml.org 
[lkml]   [2000]   [Feb]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: Network socket disconnect unreliable
Date
From
> 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/

\
 
 \ /
  Last update: 2005-03-22 13:56    [W:0.636 / U:1.084 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site