连接超时在 select() 调用的上下文中意味着什么

发布于 2024-10-05 16:30:28 字数 218 浏览 0 评论 0原文

我注意到有时 select 返回并在 errno 上设置了连接超时,但我不知道为什么它会这样做,它怎么知道?你打算如何处理这个问题? (我猜这意味着其中一个连接超时,也许在适当的时间没有听到 ACK)。我想唯一合法的情况是如果服务器套接字在那里并且您之前运行过非阻塞连接?在这种情况下,再次在此套接字上运行连接将返回给您,无论它是否已连接,这将是处理该问题的方法......但是有更好的方法吗?

提前致谢。

I've noticed that sometimes select returns with Connection Timed out set on errno, but I dont know why it would do this, how would it know? And how are you suppose to deal with this? (Im guessing it means that one of the connections timed out, perhaps an ACK wasnt heard back from at an appropriate time). Id imagine the only legit case of this would be if a server socket is in there and you ran a nonblocking connect before? In which case running a connect on this socket again would return to you whether it was connected or not, and that would be the way to handle that.... but is there a better way?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过去的过去 2024-10-12 16:30:28

正如上面的评论者所说,这可能是非阻塞 connect() 上的 select() 的结果。除非这通常是超时,在这种情况下,传入接受的 TCP 套接字有时也会发生这种情况。不管怎样,下面是两个非常有用的指南,可以帮助您回忆一下 select() 的使用:

http://www.lowtek.com/sockets/select.html

http://beej.us/guide/bgnet/output/html/multipage/advanced.html#select

http://beej.us/guide/bgnet/output/html/multipage/advanced.html#blocking

另请参阅此问题的 Python 示例:

How can I get non-阻塞套接字 connect() 的?

干杯。

As the commenter above said, this is probably the result of a select() on a non-blocking connect(). Unless this is a timeout in general, in which case it can happen for incoming accepted TCP sockets as well sometimes. Either way, below are two very useful guides to refresh your memory on the usage of select():

http://www.lowtek.com/sockets/select.html

http://beej.us/guide/bgnet/output/html/multipage/advanced.html#select

http://beej.us/guide/bgnet/output/html/multipage/advanced.html#blocking

See also this question for a Python example:

How can I get non-blocking socket connect()'s?

Cheers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文