Subject: Dumb/silly network programming question
To: #List NetBSD current users <current-users@NetBSD.ORG>
From: Paul Goyette <>
List: current-users
Date: 12/06/2003 07:30:45
How does one tell if a TCP socket has been disconnected without trying
to write to the socket?

If the remote end closes the socket normally, all is OK.  But if the
remote process is SIGKILLed, my listener is notified via select(2)
that the socket is available for reading.  Yet when I read from the
socket, I get zero data returned and errno=EAGAIN.  Since the same
errno is returned if the socket is empty, how can I distinguish that
that remote end is gone?

I've tried getsockopt(2) to check SO_ERROR but it comes back zero
every time.

Anyone got a clue-by-four?

|   Paul Goyette   | PGP DSS Key fingerprint: |  E-mail addresses:   |
| Network Engineer | FA29 0E3B 35AF E8AE 6651 |   |
|  & World Cruiser | 0786 F758 55DE 53BA 7731 | |