调整套接字连接调用超时
在 Win32 环境中是否有任何方法可以“调整”套接字 connect()
调用的超时? 具体来说,我想增加超时长度。
使用的套接字是非阻塞的。
Is there any way in a Win32 environment to "tune" the timeout on a socket connect()
call? Specifically, I would like to increase the timeout length.
The sockets in use are non-blocking.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,这是可能的。
如果您在
之后处于非阻塞模式connect()
,通常使用select()
等待 I/O 准备就绪。 该函数有一个参数用于指定超时值,超时时将返回 0。Yes, this is possible.
If you're in non-blocking mode after
connect()
, you normally useselect()
to wait till I/O is ready. This function has a parameter for specifying the timeout value and will return 0 in case of a timeout.您可以尝试使用 SO_RCVTIMEO 和 SO_SNDTIMEO 套接字选项来设置任何套接字操作的超时。 示例:
您还可以尝试alarm()。 样本:
You can try to use SO_RCVTIMEO and SO_SNDTIMEO socket options to set timeouts for any socket operations. Example:
You can also try alarm(). Sample:
不,这是不可能的。 默认连接超时可以减少,但不能增加。
No, this is not possible. The default connect timeout can be decreased, but not increased.