KEEPALIVES and SIGPIPE

James H. Coombs JAZBO at brownvm.brown.edu
Sat Mar 3 04:26:36 AEST 1990


Jerome Freedman asks:

         If I have a a TCP socket with KEEPALIVE set and if there is no
         activity on that socket will a SIGPIPE be generated if the other side
         closes the connection? if the other side crashes (in other words will
         the keepalive packets cause a SIGPIPE)

In my experience, the KEEPALIVE never takes place once the client dies.
Instead, my server's recv() invocation returns with 0 bytes read, which I
interpret as a dead client.  Since my recv() calls block, there is no other
reason to return with 0 bytes.  That approach has worked in heavy use for a
year now, on both SUN and A/UX.  Note that this is not something that I
planned to do based upon examples and documentation.  In fact, I have no
choice but to interpret this as an error at some level, and it turns out to be
an error at the IPC level instead of the application's protocol.

There is one exception to this.  If I reboot the client's machine, then the
server's recv() continues to block, and KEEPALIVE packets go off as scheduled.
SIGPIPE does not occur until the appropriate number of attempts have taken
place.  The timing of KEEPALIVE is controlled by the kernel, although it would
be useful to have it under application control.  If I allow the client machine
to come back up before KEEPALIVE has timed out, recv() returns with 0 bytes.

Can anyone explain this behavior?

--Jim

Dr. James H. Coombs
Senior Software Engineer, Research
Institute for Research in Information and Scholarship (IRIS)
Brown University, Box 1946
Providence, RI 02912
jazbo at brownvm.bitnet
Acknowledge-To: <JAZBO at BROWNVM>



More information about the Comp.unix.questions mailing list