[IRCServices Coding] ircservices5.0a28 various

V13 v13 at it.teithe.gr
Sun Apr 14 13:18:00 PDT 2002


On Monday 15 April 2002 03:54, Andrew Church wrote:
>      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.

You do a connect().
If connect returns 0 then the connection is established.
If it returns -1 then you select() this fd for write.
When select() indicates writeability then you use getsockopt():

int	ret,n;
ret=getsockopt(sockfd,SOL_SOCKET,SO_ERROR,&n,sizeof(n));

ret==0 && n==0 means the socket is succesfuly connected
when failed n has the same error code that connect() whould return if it was a 
blocking socket.

>   --Andrew Church
<<V13>>