关于 SO_RCVTIMEO and SO_SNDTIMEO

146 views
Skip to first unread message

Marmot

unread,
Mar 9, 2012, 3:03:42 AM3/9/12
to TopLanguage
在使用winsocket时,打算通过SO_RCVTIMEO 以及 SO_SNDTIMEO 来实现recv 以及 send 的超时判断.
使用前在找了msdn看了一下,有一句话没有看懂:
If a send or receive operation times out on a socket, the socket
state is indeterminate, and should not be used; TCP sockets in this
state have a potential for data loss, since the operation could be
canceled at the same moment the operation was to be completed.

在网上查了一个帖子( http://www.unixresources.net/linux/lf/58/archive/00/00/13/19/131928.html
),帖子中有这样的解释:

QUOTE
One more thing it is specified that, while using
setsockopt(SO_RCVTIMEO) "If a send or receive operation times out on a
socket, the socket state is indeterminate, and should not be used; TCP
sockets in this state have a potential for data loss, since the
operation could be canceled at the same moment the operation was to be
completed."

Right, because this times out the actual operation, not the
attempt to
get the results of the operation or the attempt to initiate it.

仍旧云里雾里.下面列举问题:

什么是 actual operation?
为什么实现这种超时的很多代码选择 select/poll + non-blocking socket?

Marmot

unread,
Mar 9, 2012, 3:05:17 AM3/9/12
to TopLanguage
少问了一个问题:
什么情况下会出现 data loss?

On 3月9日, 下午4时03分, Marmot <realwan...@gmail.com> wrote:
> 在使用winsocket时,打算通过SO_RCVTIMEO 以及 SO_SNDTIMEO 来实现recv 以及 send 的超时判断.
> 使用前在找了msdn看了一下,有一句话没有看懂:
> If a send or receive operation times out on a socket, the socket
> state is indeterminate, and should not be used; TCP sockets in this
> state have a potential for data loss, since the operation could be
> canceled at the same moment the operation was to be completed.
>
> 在网上查了一个帖子(http://www.unixresources.net/linux/lf/58/archive/00/00/13/19/131928.html
Reply all
Reply to author
Forward
0 new messages