aboutsummaryrefslogtreecommitdiff
path: root/src/netbase.cpp
diff options
context:
space:
mode:
authorVasil Dimov <vd@FreeBSD.org>2020-12-04 15:10:09 +0100
committerVasil Dimov <vd@FreeBSD.org>2021-03-01 13:22:17 +0100
commit34bcfab562bac9887ca9c3831cf4fd0ee7f98149 (patch)
tree228081518170d88fff2559c53e5fce172bfdf432 /src/netbase.cpp
parentcff65c4a270887ec171293409ab84f5d0d0be7fc (diff)
downloadbitcoin-34bcfab562bac9887ca9c3831cf4fd0ee7f98149.tar.xz
net: move the constant maxWait out of InterruptibleRecv()
Move `maxWait` out of `InterruptibleRecv()` and rename it to `MAX_WAIT_FOR_IO` so that it can be reused by other code.
Diffstat (limited to 'src/netbase.cpp')
-rw-r--r--src/netbase.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/netbase.cpp b/src/netbase.cpp
index 0c5b3a220e..5a714f0026 100644
--- a/src/netbase.cpp
+++ b/src/netbase.cpp
@@ -14,6 +14,7 @@
#include <util/time.h>
#include <atomic>
+#include <chrono>
#include <cstdint>
#include <functional>
#include <limits>
@@ -360,9 +361,6 @@ static IntrRecvError InterruptibleRecv(uint8_t* data, size_t len, int timeout, c
{
int64_t curTime = GetTimeMillis();
int64_t endTime = curTime + timeout;
- // Maximum time to wait for I/O readiness. It will take up until this time
- // (in millis) to break off in case of an interruption.
- const int64_t maxWait = 1000;
while (len > 0 && curTime < endTime) {
ssize_t ret = sock.Recv(data, len, 0); // Optimistically try the recv first
if (ret > 0) {
@@ -373,10 +371,11 @@ static IntrRecvError InterruptibleRecv(uint8_t* data, size_t len, int timeout, c
} else { // Other error or blocking
int nErr = WSAGetLastError();
if (nErr == WSAEINPROGRESS || nErr == WSAEWOULDBLOCK || nErr == WSAEINVAL) {
- // Only wait at most maxWait milliseconds at a time, unless
+ // Only wait at most MAX_WAIT_FOR_IO at a time, unless
// we're approaching the end of the specified total timeout
- int timeout_ms = std::min(endTime - curTime, maxWait);
- if (!sock.Wait(std::chrono::milliseconds{timeout_ms}, Sock::RECV)) {
+ const auto remaining = std::chrono::milliseconds{endTime - curTime};
+ const auto timeout = std::min(remaining, std::chrono::milliseconds{MAX_WAIT_FOR_IO});
+ if (!sock.Wait(timeout, Sock::RECV)) {
return IntrRecvError::NetworkError;
}
} else {