SOCK_STREAM socket listen () calls TCP syn / ack to send

I have a socket configured to accept TCP connections with

socket(AF_INET, SOCK_STREAM, 0) 

and then I call bind() , listen() and accept()

The problem is that when I call listen (), it causes the SYN / ACK packet to be sent to the client. I thought this would not happen until I call accept (), but worse than that, the SYN / ACK packet does not have a confirmation incremented by one.

What causes this, and how can I fix it?

thanks

As a side note - does it matter that my TCP connection is asymmetric?

+4
source share
2 answers

This is a normal TCP backlog queue operation. This is a queue of connections that the stack has already completed, but the application has not yet been accepted. The size of this queue is given by the second argument to listen on (), although the platform can adjust it up or down (usually up).

Everything that you observed the serial number should also be correct, otherwise nothing happened.

+2
source

A TCP implementation on your computer can actually "accept" an incoming connection the moment you call listen . It really makes sense to avoid unnecessary delays due to "lazy" accepts. Recall that one of the listen parameters is the so-called number of lags, that is, the number of "buffered" takes pending.

Regarding the ACK increment in the syn + ack datagram. I don’t remember what the protocol says, but this is probably the correct behavior during a handshake.

+3
source

Source: https://habr.com/ru/post/1444479/


All Articles