Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
为什么我的服务器套接字在listen(severFd,2)连接 3 个终端的情况下监听?
listen(severFd,2)
它应该限制为 2。有人知道为什么吗?
第二个参数listen()表示排队的传入请求的最大数量。这不是可以接受的连接数的最大值。
listen()
从man listen(其中backlog是第二个参数的名称):
backlog 参数定义了 sockfd 的挂起连接队列可以增长到的最大长度。
如果最多需要两个接受的连接,那么您必须明确编码。