Subject: Re: Dumb/silly network programming question
To: Paul Goyette <firstname.lastname@example.org>
From: Bill Studenmund <email@example.com>
Date: 12/09/2003 18:06:16
Content-Type: text/plain; charset=us-ascii
On Sat, Dec 06, 2003 at 07:30:45AM -0800, Paul Goyette wrote:
> 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=3DEAGAIN. Since the same
> errno is returned if the socket is empty, how can I distinguish that
> that remote end is gone?
Uhm, getting back zero data means you hit the end. If there is nothing to=
read but the connections is still alive, you'll get -1 and errno will be=20
=46rom man read:
If successful, the number of bytes actually read is returned. Upon re=
ing end-of-file, zero is returned. Otherwise, a -1 is returned and the
global variable errno is set to indicate the error.
Note that errno only matters if you get back a -1.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (NetBSD)
-----END PGP SIGNATURE-----