为什么当我连接的套接字多于给定监听的参数 backlog 时我没有收到错误消息?

Why I don't get an error when I connect more sockets than the argument backlog given to listen?

我有一个被动套接字可以监听这样的连接:

t = listen(fd, 1); 

fd是之前创建的socket的文件描述符
如您所见,如果我理解得很好,listen() 应该只能将一个传入套接字放入其待处理连接队列中(因为其积压参数 = 1)。但是如果我尝试将多个套接字连接到被动套接字,我不会收到任何错误。我预计会出现 ECONNREFUSED 错误,因为队列已满。

为什么我不见了?

根据 man listen(2),强调我的:

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.

如果您使用的是 TCP 套接字,则该行为是预期的,因为 TCP 支持重传。