connecting to non-responding hosts: 1 hr timeout (fwd)
Dave Dykstra
dwd at bell-labs.com
Thu May 3 05:32:58 EST 2001
On Tue, May 01, 2001 at 08:37:38PM -0700, Carson Gaspar wrote:
>
>
> --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 didn't say my approach was all that portable but Peter Gutmann said his
way was.
> 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.
I'd say just ifdef out the whole thing if on Unix and SO_ERROR is missing.
It's definitely worth doing on the modern unixes. You got it working in
socks5 so ssh could use that approach. Where's the code for it in socks5?
The reason I needed it in ssh was that I wanted to use ssh to initialize
/etc/ssh_known_hosts from the list of hosts in /etc/hosts.equiv but there
were a lot of dead hosts in there and it was taking forever to go through
the whole list.
- Dave Dykstra
More information about the openssh-unix-dev
mailing list