I have a passive socket that listen connections like this:
t = listen(fd, 1);
fd
is the file descriptor of the socket created before.
As you can see and if I understand well, listen() should be able to place only one incoming socket in its queue of pending connections (because its backlog argument = 1). But if I try to connect several sockets to the passive one, I don't get any error. And I expect to have a ECONNREFUSED
error because the queue is full.
Why am I missing?
As per man listen(2)
, emphasis mine:
The backlog argument defines the maximum length to which the queue of pending connections for sockfd may grow. If a connection request arrives when the queue is full, the client may receive an error with an indication of ECONNREFUSED or, if the underlying protocol supports retransmission, the request may be ignored so that a later reattempt at connection succeeds.
If you're using TCP sockets, then the behaviour is expected, as TCP supports retransmission.