WinSock recv () timeout: setsockopt () - set value + half a second?

I am writing a cross-platform library that, among other things, provides a socket interface, and during the launch of my unit-test package, I noticed something strange with respect to timeouts set via setsockopt() : On Windows, locking It seems like a call recv() returns in about half a second (500 ms) later than indicated by the SO_RCVTIMEO option.

Is there any explanation for this in the docs I skipped? Searching the Internet, I was able to find one other link to the problem - could someone who owns "Windows Sockets Network Programming" Bob Quinn and Dave Jester look for page 466 for me? Unfortunately, I can now run my Windows Server 2008 R2 test, does the other version of Windows have the same strange behavior?

+1
source share
2 answers

I have the same problem. Taking advantage

patchedTimeout = max (unpatchedTimepit - 500, 1)

Tested with unpatchedTimepit == 850

0
source

From Network Programming for Microsoft Windows from Jones and Ohlund:

SO_RCVTIMEO optval


  • Type: int
  • Get / Set: both
  • Winsock Version: 1 +
  • Description: Gets or sets the timeout value (in milliseconds) associated with receiving data on the Socket

The SO_RCVTIMEO parameter sets to receive the timeout value when locking the connector. The timeout value is an integer in milliseconds, which indicates how long the Winsock function should be blocked when trying to receive data. If you need to use SO_RCVTIMEO and you use the WSASocket function to create a socket, you must specify WSA_FLAG_OVERLAPPED as part of the WSASocket dwFlags parameter. Subsequent calls to any Winsock receive function (for example, recv, recvfrom, WSARecv or WSARecvFrom) will be blocked only for the time specified. If data does not arrive within this time, the call fails with error 10060 (WSAETIMEDOUT). If the receiver times out, the socket is in an undefined state and should not be used.

For performance reasons, this option was disabled in Windows CE 2.1. if you try to set this parameter, it is silently ignored and returns without fail. Previous versions of Windows CE performed this option.

I think the important information in this is:

If you need to use the SO_RCVTIMEO parameter, and you use WSASocket to create a socket, you must specify WSA_FLAG_OVERLAPPED as part of the WSASocket dwFlags parameter

I hope this is still useful :)

+2
source

Source: https://habr.com/ru/post/908705/


All Articles