[IRCServices Coding] ircservices5.0a28 various
Andrew Church
achurch at achurch.org
Mon Apr 15 00:54:40 PDT 2002
>I believe the POSIX way to do this is to call connect(), ignore the return
>value, then select() it for except and write. If write, it opened
>successfully, if except, there's an error (use getsockopt()).
Do you know of anywhere this is documented? My connect(2) man page
(Linux, dated 1998/10/3) says, for EINPROGRESS:
The socket is non-blocking and the connection cannot be completed
immediately. It is possible to select(2) or poll(2) for
completion by selecting the socket for writing. After select
indicates writability, use getsockopt(2) to read the SO_ERROR
option at level SOL_SOCKET to determine whether connect completed
successfully (SO_ERROR) is zero) or unsuccessfully (SO_ERROR is
one of the usual error codes listed here, explaining the reason
for the failure).
which would seem to indicate that Linux, at least, returns writable even
for unsuccessful connections (I haven't tested this).
If anyone would be willing to try to figure out and test a reliable
way to check for connectedness of non-blocking sockets on both Linux and
FreeBSD, it would be much appreciated. Remember that it has to work for
both successful and failed connections for both localhost (I'm not sure,
but connect() may return success even if non-blocking for 127.0.0.1) and
remote hosts with reasonably high (>100ms) ping times.
--Andrew Church
achurch at achurch.org
http://achurch.org/