听()忽略积压的说法? [英] listen() ignores the backlog argument?
问题描述
我有以下问题:
我 =的sockfd插座(AF_INET,SOCK_STREAM,0)
我建立并绑定插座后(让我们以 sockfd.sin_port = htons说,(666)
),我马上做的:
After I set up and bind the socket (let's say with sockfd.sin_port = htons(666)
), I immediately do:
listen(sockfd, 3);
sleep(50); // for test purposes
我睡50秒,以测试积压的说法,这似乎被忽略,因为我可以建立在端口666连接* 3倍以上。
I'm sleeping for 50 seconds to test the backlog argument, which seems to be ignored because I can establish a connection* more than 3 times on port 666.
*:我的意思是,我得到每个第N个SYN(N> 3)从客户端发送并放置在监听队列,而不是被掉了SYN / ACK。可能是什么问题?我读过的手册页听(2)和tcp(7),并发现:
*: What I mean is that I get a syn/ack for each Nth SYN (n>3) sent from the client and placed in the listen queue, instead of being dropped. What could be wrong? I've read the man pages of listen(2) and tcp(7) and found:
这是TCP套接字积压参数使用Linux 2.2改变的行为。
现在它规定了完全建立套接字等待被接受的,而不是不完全的连接请求的数目,队列长度。队列的最大长度不完整的插座即可
使用设置
的/ proc / SYS /网/的IPv4 / tcp_max_syn_backlog。
当syncookies的启用有
没有逻辑最大长度和这
设置将被忽略。见TCP(7),用于
更多
信息。
The behavior of the backlog argument on TCP sockets changed with Linux 2.2. Now it specifies the queue length for completely established sockets waiting to be accepted, instead of the number of incomplete connection requests. The maximum length of the queue for incomplete sockets can be set using /proc/sys/net/ipv4/tcp_max_syn_backlog. When syncookies are enabled there is no logical maximum length and this setting is ignored. See tcp(7) for more information.
,但即使有的sysctl -w sys.net.ipv4.tcp_max_syn_backlog = 2
和的sysctl -w net.ipv4.tcp_syncookies = 0
,我仍然得到同样的结果!我必须失去了一些东西或完全missunderstand 听()
的积压目的。
, but even with sysctl -w sys.net.ipv4.tcp_max_syn_backlog=2
and sysctl -w net.ipv4.tcp_syncookies=0
, I still get the same results! I must be missing something or completely missunderstand listen()
's backlog purpose.
推荐答案
积压参数听()
只是建议性的。
The backlog argument to listen()
is only advisory.
积压的说法提供了提示
要实施该
实现应使用限制
在未完成的连接数
套接字的侦听队列。
The backlog argument provides a hint to the implementation which the implementation shall use to limit the number of outstanding connections in the socket's listen queue.
Linux内核轮它到2的下一个最高功率的当前版本,用最少的16 revelant code是在 reqsk_queue_alloc()。
Current versions of the Linux kernel round it up to the next highest power of two, with a minimum of 16. The revelant code is in reqsk_queue_alloc().
这篇关于听()忽略积压的说法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!