Subject: Sensing a disconnected socket
To: None <current-users@NetBSD.ORG>
From: Rick Byers <>
List: current-users
Date: 06/19/1997 16:32:38
Hi Everyone,
Sorry this is a little off topic, but it might be partly NetBSD specific,
so I'll ask anyway.

I'd like to be able to tell when a socket (TCP Stream) has been
disconnected without writing to it.  I've got a cgi that writes stuff now
and then, but usually just waits.  If the user stops the transfer, I need
the process to exit.  Normally, it just sits there with the socket in the
FIN_WAIT_2 state until the process is killed.  I was writing a NUL to the
socket every 2 seconds, which works, but isn't ideal.  If something gets
writen when the socket is in that state, the process gets SIGPIPE and

Ideally the process will exit as soon as the user stops the transfer, but
as far as I can tell, no signal (SIGPIPE, SIGURG etc..) is delivered to
the process when the socket in intially closed.  I can just have a 1
second interval alarm to check (and possibly exit) if the socket has been
closed.  How can I tell that it has been closed?  I can't seem to find any
functions that will return that information.


Rick Byers                                      Internet Access Worldwide                                System Admin, Tech Support
Welland, Ontario, Canada                                    (905)714-1400