in reply to Re^3: Detecting Dead Socket Connection
in thread Detecting Dead Socket Connection

Yes! You are correct sir! Drawing from c experience, I went with somethink like this:
#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

    How perl handles an ungraceful socket disconnections is largely a function of how the underlying TCP stack handles it. I don't think you'll get much, if any, better than this.