14
14
#include < util/time.h>
15
15
16
16
#include < atomic>
17
+ #include < chrono>
17
18
#include < cstdint>
18
19
#include < functional>
19
20
#include < limits>
@@ -360,9 +361,6 @@ static IntrRecvError InterruptibleRecv(uint8_t* data, size_t len, int timeout, c
360
361
{
361
362
int64_t curTime = GetTimeMillis ();
362
363
int64_t endTime = curTime + timeout;
363
- // Maximum time to wait for I/O readiness. It will take up until this time
364
- // (in millis) to break off in case of an interruption.
365
- const int64_t maxWait = 1000 ;
366
364
while (len > 0 && curTime < endTime) {
367
365
ssize_t ret = sock.Recv (data, len, 0 ); // Optimistically try the recv first
368
366
if (ret > 0 ) {
@@ -373,10 +371,11 @@ static IntrRecvError InterruptibleRecv(uint8_t* data, size_t len, int timeout, c
373
371
} else { // Other error or blocking
374
372
int nErr = WSAGetLastError ();
375
373
if (nErr == WSAEINPROGRESS || nErr == WSAEWOULDBLOCK || nErr == WSAEINVAL) {
376
- // Only wait at most maxWait milliseconds at a time, unless
374
+ // Only wait at most MAX_WAIT_FOR_IO at a time, unless
377
375
// we're approaching the end of the specified total timeout
378
- int timeout_ms = std::min (endTime - curTime, maxWait);
379
- if (!sock.Wait (std::chrono::milliseconds{timeout_ms}, Sock::RECV)) {
376
+ const auto remaining = std::chrono::milliseconds{endTime - curTime};
377
+ const auto timeout = std::min (remaining, std::chrono::milliseconds{MAX_WAIT_FOR_IO});
378
+ if (!sock.Wait (timeout, Sock::RECV)) {
380
379
return IntrRecvError::NetworkError;
381
380
}
382
381
} else {
0 commit comments