[IRCServices Coding] ircservices5.0a28 various

V13 v13 at it.teithe.gr
Sun Apr 14 05:22:01 PDT 2002


On Sunday 14 April 2002 14:46, Andrew Church wrote:
>      "Already connected" sounds like it's ignoring the fact that the socket
> is non-blocking (or maybe my logic is wrong).

I'm not 100% sure about this.. anyway...

In sockets.c:482:

if ((i = connect(fd, (struct sockaddr *)&sa, sizeof(sa))) < 0
        && errno != EINPROGRESS

and after that:

if (i == 0) {
        s->flags |= SF_CONNECTED;
        FD_SET(fd, &sock_fds);
        if (s->cb_connect)
            s->cb_connect(s, 0);
    } else {
        s->flags |= SF_CONNECTING;
        FD_SET(fd, &write_fds);
    }

So a non blocking connect() returns EINPROGRESS and (s->flags & SF_CONNECTING) 
is true..

After that, when the connection is established, in sockets.c:296 in function 
check_sockets():

} else if (s->flags & SF_CONNECTING) {
                /* Connection established (or failed) */
                if (debug >= 2)
                    log("debug: sockets: connect on fd %d returned", i);
                res = connect(s->fd, (struct sockaddr *)&s->remote,
                              sizeof(s->remote));

So you're calling connect() twice and the 2nd call is done when the socket 
*IS* connected, since writeability indicates the connection is established.

>   --Andrew Church
<<V13>>