WinSock recv() 超时:setsockopt()-设置值 + 半秒? [英] WinSock recv() timeout: setsockopt()-set value + half a second?

查看:40
本文介绍了WinSock recv() 超时:setsockopt()-设置值 + 半秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个跨平台库,其中提供了一个套接字接口,在运行我的单元测试套件时,我注意到通过 setsockopt():在 Windows 上,阻塞的 recv() 调用似乎始终比通过 SO_RCVTIMEO 选项指定的时间晚半秒(500 毫秒)返回.

I am writing a cross-platform library which, among other things, provides a socket interface, and while running my unit-test suite, I noticed something strange with regard to timeouts set via setsockopt(): On Windows, a blocking recv() call seems to consistently return about half a second (500 ms) later than specified via the SO_RCVTIMEO option.

在我错过的文档中对此有任何解释吗?在网上搜索,我只能找到 该问题的其他参考 – 拥有»Windows 套接字的人可以吗网络编程« Bob Quinn 和 Dave Shute 为我查找第 466 页?不幸的是,我现在只能运行我的测试 Windows Server 2008 R2,其他 Windows 版本是否也存在同样的奇怪行为?

Is there any explanation for this in the docs I missed? Searching the web, I was only able to find a single other reference to the problem – could somebody who owns »Windows Sockets Network Programming« by Bob Quinn and Dave Shute look up page 466 for me? Unfortunately, I can only run my test Windows Server 2008 R2 right now, does the same strange behavior exist on other Windows versions as well?

推荐答案

我遇到了同样的问题.准备使用

I am having the same problem. Going to use

patchedTimeout = max ( unpatchedTimepit - 500, 1 )

patchedTimeout = max ( unpatchedTimepit - 500, 1 )

使用 unpatchedTimepit == 850 对此进行了测试

Tested this with the unpatchedTimepit == 850

这篇关于WinSock recv() 超时:setsockopt()-设置值 + 半秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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