connecting to non-responding hosts: 1 hr timeout (fwd)

Carson Gaspar carson at taltos.org
Wed May 2 13:37:38 EST 2001



--On Tuesday, May 01, 2001 2:35 PM -0500 Dave Dykstra <dwd at bell-labs.com> 
wrote:

>> you just need to do fcntl(fd, F_SETFL, O_NONBLOCK) on the socket before
>> the connect(), check for EINPROGRESS from the connect(), and then do a
>> select() for writability on the fd with a timeout of however long you
>> want.  Note that if the connection is then refused it will come as an
>> error message from the next read() or write().  Some older systems may
>> not have O_NONBLOCK or EINPROGRESS defines so I'd #ifdef out the code if
>> they're missing.

Sadly, this is _not_ portable, as you seem to imply by your portable url 
below. I'm one of the people who got async connect working with socks5. 
When I asked the late Richard Stevens about some edge conditions, his 
response was "I don't know. Let me know what you find out". Here There Be 
Dragons. I ended up writing a test case bit of C code, and running it on a 
bunch of different OSs. It wasn't pretty. The main problem lies in getting 
the return code from the async connect if it fails. The only portable way 
is via getsockopt(), and many older systems don't support the SO_ERROR 
option. What select returns on a failed call is also 
implementation-specific.

> On Wed, May 02, 2001 at 06:33:28AM +1200, Peter Gutmann wrote:
> ...
>> I wrote my own wrappers for this which work under
>> every Unix I've been able to get my hands on as well as Win32, if
>> whoever's working on this for GPG wants the code they can grab it from
>> the latest cryptlib version,
>> ftp://ftp.franken.de/pub/crypt/cryptlib/beta/cl30beta05.zip, as
>> misc/net_tcp.c.

Sadly, this relies on SO_ERROR being present and working properly. This 
should be true for any modern flavor of UNIX, but older implementations 
will fail, FYI. The comments in misc/net_tcp.c explain things correctly, 
however.

-- 
Carson









More information about the openssh-unix-dev mailing list