gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 23:21:45 25 4
gpt4 key购买 nike

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

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 支持重传。

关于c - 为什么当我连接的套接字多于给定监听的参数 backlog 时我没有收到错误消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37609951/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com