in reply to Re^3: Detecting Dead Socket Connection
in thread Detecting Dead Socket Connection
#Passive check for down socket my $sin = ""; vec($sin, fileno(SESSION),1 ) = 1; my $nfound = select($sin, undef, undef, .01); if ($nfound != 0){ if( eof(SESSION) == 1 ){ die "Socket is dead on passive check\n"; } }
Here I told select to time out after .01 seconds. If the connection goes down (gracefully) then $nfound returns something greater than 0 (the disconnect packet?) but an eof on the socket then determines that socket handle SESSION is at EOF and so the program dies, or whatever.
It is worth noting, however, that if the connection does NOT go down gracefule, like the remote network cable comes unplugged, then this does not work as expected. Select WILL return 0.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Detecting Dead Socket Connection
by Tanktalus (Canon) on Mar 19, 2005 at 00:26 UTC |