Connect (), accept () and select () sequence sequence

I'm new to C.


I just noticed that connect()the client-side function can return until the three-way TCP jitter ends. I mean, it connect()can even go back to the accept()server side call (correct me if I am wrong).

Based on this knowledge, my question is that when I then call select()on the client side and watch the file descriptor, waiting for it to write when select()it returns successfully, it means that the server side has already called accept(), and now I can safely write to the server, right? Thanks so much for your time.

int flags = fcntl(fd, F_GETFL);

flags |= O_NONBLOCK;

fcntl(fd, F_SETFL, flags);

if (connect(fd, (struct sockaddr *)saptr, salen) < 0)
{
    if (errno != EINPROGRESS)
        /* error_return */
}

fd_set set;
FD_ZERO (&set);

FD_SET (fd, &set);

select (FD_SETSIZE, NULL, &set, NULL, &timeout)
/* Here, if select returns 1, that means accept() is already called 
   on the server side, and now I can safely write to the server, right? */
+4
2

select() , , accept()

, . connect() , , , . . accept() .

, ?

, "", , , , select() promises . , , . , . , accept() , .

: , , accept() ed ( ). , accept() , .

+3

' , connect() accept() "

, .

select() , , select() , , accept() , ?

. :)

-1
source

All Articles