在 Windows XP 上的许多非阻塞连接 TCP 套接字上使用 select() 丢失连接
我有一个小型便携式工具,可以连接到不同地点的大约 150 台服务器,以便快速检查它们的状态。相对快速地将所有服务器的状态返回给用户非常重要,因此该工具使用非阻塞连接并行连接到服务器,并使用 select() 来确定每个套接字何时准备就绪。 select() 的使用相当简单,该工具现在已经非常成熟,并且在 Linux 上运行良好。它在 Windows XP 上运行,但与绝大多数服务器的连接无法完成。该工具会错开连接调用,以避免产生类似 SYN 洪水的情况。它连接到一台服务器的时间约为 100 毫秒。我还进行了检查以确保 FD_SETSIZE 不被违反。我从其他人那里得到了一些轶事证据,表明该行为在更高版本的 Windows 上更好,但尚未能够验证。
我已经使用 WinDump 来验证 syn 数据包是否正在发送,并且我可以看到 ack 数据包返回,但 select() 始终返回零,并且代码根本无法连接到大多数确实存在的服务器,并且我可以在 Linux 上使用相同的代码很好地连接。
有没有人在 Windows XP 上看到和/或解决过许多非阻塞连接和选择的类似问题?
I have a small portable tool which connects to around 150 servers at diverse locations to get a quick status check from them. It is important to get the status for all servers back to the user relatively quickly so the tool connects to the servers in parallel using non-blocking connect, and uses select() to determine when each socket is ready. The use of select() is fairly straightforward, and the tool is failure mature now and works well on Linux. It runs on windows xp, but connections to the vast majority of the servers out there do not complete. The tool staggers the calls to connect to avoid creating what looks like a SYN flood. It connects to one server about 100 msecs. I also have a check in place to ensure FD_SETSIZE is not violated. I have anecdotal evidence from someone else that the behaviour is better on later windows versions, but have not been able to verify.
I have used WinDump to verify that the syn packets are being sent, and I can see ack packets coming back, but select() keeps returning zero, and the code simply can't connect to most of the servers that do exist, and I can connect to just fine with the same code on Linux.
Has anyone seen and or solved any similar issues with many non-blocking connects and select on Windows XP?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过一天左右的挖掘,我似乎找到了答案。在 Windows XP SP2 上,系统范围内的并发连接套接字数量限制为 10 个。如果存在 10 个或更多半打开连接,则会记录一个系统事件,指出已达到限制,并且新的连接套接字将被静默限制。系统事件编号为 4226。
我通过添加 Windows XP 的版本检查来修复我的代码,并将这些系统上的连接限制为少于 10 个。到目前为止,我还没有收到其他版本受到影响的报告。
After another day or so of digging I seem to have found the answer. On windows XP SP2 there is a limit of 10 concurrent connecting sockets system wide. If 10 or more half open connections exist, a System event is logged noting that the limit has been reached, and new connecting sockets are throttled silently. The System Event number is 4226.
I have fixed my code by adding version checks for Windows XP, and throttled to less than 10 connections on those systems. So far I have no reports of other versions being affected.