nTimeout=10;
NErr=setsockopt (s, SOL_SOCKET, SO_RCVTIMEO, (char *) & amp; NTimeout, sizeof (nTimeout));
At the time of the UDP receives
CCpuTimer T0;
T0. Start (); Start the timer
//UDP socket set to blocking mode receives
NRet=recvfrom (g_stNet2Can sockDevice, (char *) byteBuffer, nBytes, 0, (struct sockaddr *) & amp; Sin, & amp; NLen);
If (nRet!=nBytes)
{
NRet=WSAGetLastError ();
//if (nRet!
=10035){
TRACE (_T (UDP recvfrom "error: % d - tm: % d us \ n"), nRet, T0. Getus ());
}
return -1;
}
When not connected to, or break when the server,
Tm: UDP recvfrom error: 10060-510144 us
The timeout is above 500 ms, no matter how much
Settings
But if the timeout is set to 1000 ms, the timeout will become more than 1000 ms
CodePudding user response:
SO_RCVTIMEO and SO_SNDTIMEO do not work on all the socket operations, you should use non - blocking mode and the select.
The behaviour may change on The company operating The system configurations. On my system The connect timeouts after two times The value of I set in SO_RCVTIMEO. A quick hack like setting SO_RCVTIMEO to x/2 before A connect and x after it works, but The proper solution is using The select.