Detecting Closed Sockets

Fletcher Kittredge fkittred at bbn.com
Fri Mar 22 05:10:21 AEST 1991


In article <39989 at cup.portal.com> LordBah at cup.portal.com (Jeffrey J Vanepps) writes:
>I have a problem with telling when the other side of a socket connection
>has exited.  Normally a read/recv which returns zero after select(2) says
>that there is data to be read signifies a closed connection.  In my case,
>the application can't use this technique.  Here's the situation:

So why don't you set SO_KEEPALIVE on the socket and respond to the SIGIO?
If that is a problem for you, you could have R write to the producer's socket.
If the send returns ENOCONN, then you take whatever action necessary. 
Throughput should not be a problem since the write won't block, and the
producer can ignore the message.

Note that doing your own polling is considered by many to be a more elegant
solution than setting SO_KEEPALIVE.  SO_KEEPALIVE causes additional network
load.

regards,
fletcher
Fletcher Kittredge
Platforms and Tools Group, BBN Software Products
10 Fawcett Street,  Cambridge, MA. 02138
617-873-3465  /  fkittred at bbn.com  /  fkittred at das.harvard.edu



More information about the Comp.unix.programmer mailing list