in reply to Losing Connection

Looking at the question, i would first think that the addition of select() is about the only way to get around this.

But, in thinking, when writting to a closed socket, a PIPE signal will be generated. In the event of a PIPE signal, it can be checked by either installing a handler, or ignoring the signal. Such as :

# method one $SIG{PIPE} = sub { $SERVER_DISCONNECT = 1; }; # # when printing to socket, check $SERVER_DISCONNECT # and handle if ($SERVER_DISCONNECT == 1) # method two (Posix systems only) $SIG{PIPE} = 'IGNORE'; use Errno ':POSIX'; # other code here unless (print SOCKET "$data") { if ($! == EPIPE) { # pipe error, attempt reconnection to server } else { # real error } }
More Info :Network Programming with Perl (ISBN: 0-201-61571-1)
and the she says, "well, this ones eating my popcorn"

- Matt-Fu (MZSanford)

Replies are listed 'Best First'.
(tye)Re: Losing Connection
by tye (Sage) on Jun 27, 2001 at 00:50 UTC

    Writing to a FIFO pipe that the last reader has closed will generate SIGPIPE but most (but not all) socket implementation will just have the write()/send() operation fail rather than generating the signal.

    If the server is using shutdown() to only close one side of the connection, then one has to use select to detect this without blocking.

            - tye (but my friends call me "Tye")
Re: Re: Losing Connection
by Anonymous Monk on Jun 26, 2001 at 22:40 UTC
    That was my thougt too. Nope! If the Server(!) closes the socket, no Pipe-Signal is generated. I think it is because the Server could close only his end, and the writing channel stays open. But the Server could not answer on his already closed channel.