Subject: Re: Dumb/silly network programming question
To: Paul Goyette <paul@whooppee.com>
From: Bill Studenmund <wrstuden@netbsd.org>
List: current-users
Date: 12/11/2003 09:35:15
--gr/z0/N6AeWAPJVB
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:
>=20
> > Since you're using a TCP socket, I'd suggest using read(), not recv().
>=20
> 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=
=20
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=
=20
imply the other side unsent data. :-)
Take care,
Bill
--gr/z0/N6AeWAPJVB
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (NetBSD)
iD8DBQE/2KrSWz+3JHUci9cRAgRNAJ4yH7wYeBwmNe7axyZNMLojdItQXACdHpvO
+JReDc6Y1D/4UwsP3Etu+b4=
=4e5x
-----END PGP SIGNATURE-----
--gr/z0/N6AeWAPJVB--