Why does connect() succeed even before my server did an accept()?
Answer Posted / chaitanya
Once you have done a listen() call on your socket, the kernel is primed to accept connections on it. The usual UNIX implementation of this works by immediately completing the SYN handshake for any incoming valid SYN segments (connection attempts), creating the socket for the new connection, and keeping this new socket on an internal queue ready for the accept() call. So the socket is fully open before the accept is done.
The other factor in this is the 'backlog' parameter for listen(); that defines how many of these completed connections can be queued at one time. If the specified number is exceeded, then new incoming connects are simply ignored (which causes them to be retried).
Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
How is a socket created?
What does af mean in sockets?
What is socket programming in java?
What's the difference between a socket and a port?
What is socket address?
Is there any advantage to handling the signal, rather than just ignoring it and checking for the EPIPE error? Are there any useful parameters passed to the signal catching function?
How do unix sockets work?
What is a socket file?
What is the difference between SO_REUSEADDR and SO_REUSEPORT?
Is socket a hardware or software?
What is the function of socket?
What exactly is a socket?
How many sockets can a cpu have?
What is a sae socket?
How are unix domain sockets implemented?