timeouts on connect(2) - EWOULDBLOCK, & such.

Marcus J. Ranum mjr at decuac.dec.com
Fri May 10 08:10:38 AEST 1991



	I've been trying to implement what amounts to a timeout on a
connect(2) call, and I'm unsatisfied with the results I've been getting.
Basically, I set the socket nonblocking, do the connect(), it fails,
then I select the socket for reading. First off, I get EINPROGRESS
instead of EWOULDBLOCK as TFM implies, but worst of all I don't have
an indication of whether or not the file descriptor is any good -
in the case where I select on the fd, and a very short time later I
get a connection refusal, it's hard to tell if that indeed happened.

	What's the elegant way to do this? I'd basically like to just
"connect to that machine and give me an error if it takes more than N sec"
kind of thing. Do I have to do something really gross like try to write
junk and see if it bombs? TFM for fstat implies it's useless.

	Suggestions?

mjr.



More information about the Comp.unix.questions mailing list