Winsock的接受超时 [英] Winsock accept timeout

查看:400
本文介绍了Winsock的接受超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能使用阻塞winsockets时,超时设置为接受功能?就像我们可以做的recv并通过setsockopt的发送功能?

Is it possible to set timeout to accept function when using blocking winsockets? Like we can do to recv and send function via setsockopt?

好像这是不可能的,但我要确保。

Seems like it's not possible, but I want to ensure.

推荐答案

选择功能可与超时使用。虽然,选择最常使用非阻塞套接字使用,我没有看到任何prevents通过阻塞套接字进行选择。如果选择功能超时,那么你的行为相当于接受超时。

Select function can be used with timeout. Though, select is most commonly used with non-blocking sockets, I haven't read anything that prevents passing a blocking socket to select. If the select function times out, then you have the behavior equivalent of accept timeout.

从<一个href=\"http://msdn.microsoft.com/en-us/library/windows/desktop/ms740141%28v=vs.85%29.aspx\">MSDN

参数readfds标识是可读性进行检查插座,如果插座是目前在听的状态,它会被标记为可读,如果传入的连接请求已经收到这样的<强>接受的是保证不阻塞,完成即可。对于其他的插座,那排队的数据可读性手段可用于阅读,这样来的recv,WSARecv时WSARecvFrom或recvfrom的通话保证不会阻止。

"The parameter readfds identifies the sockets that are to be checked for readability. If the socket is currently in the listen state, it will be marked as readable if an incoming connection request has been received such that an accept is guaranteed to complete without blocking. For other sockets, readability means that queued data is available for reading such that a call to recv, WSARecv, WSARecvFrom, or recvfrom is guaranteed not to block."

这应该给你你所期望的行为。

This should give you the behaviour you are expecting.

这篇关于Winsock的接受超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆