- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我有以下问题:
我有 sockfd = socket(AF_INET, SOCK_STREAM, 0)
在我设置并绑定(bind)套接字后(假设使用 sockfd.sin_port = htons(666)
),我立即执行:
listen(sockfd, 3);
sleep(50); // for test purposes
我睡了 50 秒来测试积压参数,这似乎被忽略了,因为我可以在端口 666 上建立连接*超过 3 次。
*:我的意思是,对于从客户端发送的每个第 N 个 SYN (n>3),我都会得到一个 syn/ack 并放入监听队列,而不是被丢弃。有什么问题吗?我阅读了 listen(2) 和 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
,我仍然得到相同的结果结果!我一定是遗漏了什么或者完全误解了 listen()
的积压目的。
最佳答案
listen()
的 backlog 参数只是建议性的。
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。相关代码在 reqsk_queue_alloc() 中。 .
关于c - listen() 忽略积压参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5111040/
我正在我的从机上运行此查询。 查询: 从审核中选择 ID,其中 app='accounts' 解释输出 +----+-------------+-----------------+------
我是一名优秀的程序员,十分优秀!