Subject: Re: Dumb/silly network programming question
To: Paul Goyette <>
From: Bill Studenmund <>
List: current-users
Date: 12/11/2003 09:35:15
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Dec 10, 2003 at 04:20:09PM -0800, Paul Goyette wrote:
> On Wed, 10 Dec 2003, Bill Studenmund wrote:
> > Since you're using a TCP socket, I'd suggest using read(), not recv().
> Well, since I'm emulating the telnet protocol, I have to be able to
> handle Out-of-Band data (flags argument=3DMSG_OOB), too, corresponding to
> TCP's Urgent flag (unless I've made another blunder).  I don't see a
> way to deal with MSG_OOB using read().

True. You won't get OOB data.

> Anyway, I've managed to work around it by checking for retval=3D=3D-1 and
> errno=3D=3DEAGAIN, and sending a Telnet IAC-NOP sequence to the client.
> The write detects the broken socket and shuts things down on the server
> side.

Another idea is after recv() returns EAGAIN, try a read of one byte. Then=
that can see an EOF.

Since you're using select (and I assume eventually kqueue), you should=20
only be looking at a socket that has something on it. You really never=20
should see EAGAIN; if select's working right, to not be able to read would=
imply the other side unsent data. :-)

Take care,


Content-Type: application/pgp-signature
Content-Disposition: inline

Version: GnuPG v1.2.3 (NetBSD)