aboutsummaryrefslogtreecommitdiff
path: root/src/netbase.cpp
diff options
context:
space:
mode:
authorMarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>2023-03-24 14:25:39 +0100
committerMarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>2023-04-04 12:33:49 +0200
commitfa454dcb20b9e7943cc25e6eeea72912b5f1c7b5 (patch)
tree8d93fcb527f926e5b4f2178e86929c3a33032f7d /src/netbase.cpp
parent5150e280103dd41c8a438ce72359b0f25ff23a2f (diff)
net: Use steady clock in InterruptibleRecv
Diffstat (limited to 'src/netbase.cpp')
-rw-r--r--src/netbase.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/netbase.cpp b/src/netbase.cpp
index f39a3635f4..4f78d2e31a 100644
--- a/src/netbase.cpp
+++ b/src/netbase.cpp
@@ -36,8 +36,8 @@ static Proxy nameProxy GUARDED_BY(g_proxyinfo_mutex);
int nConnectTimeout = DEFAULT_CONNECT_TIMEOUT;
bool fNameLookup = DEFAULT_NAME_LOOKUP;
-// Need ample time for negotiation for very slow proxies such as Tor (milliseconds)
-int g_socks5_recv_timeout = 20 * 1000;
+// Need ample time for negotiation for very slow proxies such as Tor
+std::chrono::milliseconds g_socks5_recv_timeout = 20s;
static std::atomic<bool> interruptSocks5Recv(false);
std::vector<CNetAddr> WrappedGetAddrInfo(const std::string& name, bool allow_lookup)
@@ -296,7 +296,7 @@ enum class IntrRecvError {
*
* @param data The buffer where the read bytes should be stored.
* @param len The number of bytes to read into the specified buffer.
- * @param timeout The total timeout in milliseconds for this read.
+ * @param timeout The total timeout for this read.
* @param sock The socket (has to be in non-blocking mode) from which to read bytes.
*
* @returns An IntrRecvError indicating the resulting status of this read.
@@ -306,10 +306,10 @@ enum class IntrRecvError {
* @see This function can be interrupted by calling InterruptSocks5(bool).
* Sockets can be made non-blocking with Sock::SetNonBlocking().
*/
-static IntrRecvError InterruptibleRecv(uint8_t* data, size_t len, int timeout, const Sock& sock)
+static IntrRecvError InterruptibleRecv(uint8_t* data, size_t len, std::chrono::milliseconds timeout, const Sock& sock)
{
- int64_t curTime = GetTimeMillis();
- int64_t endTime = curTime + timeout;
+ auto curTime{Now<SteadyMilliseconds>()};
+ const auto endTime{curTime + timeout};
while (len > 0 && curTime < endTime) {
ssize_t ret = sock.Recv(data, len, 0); // Optimistically try the recv first
if (ret > 0) {
@@ -333,7 +333,7 @@ static IntrRecvError InterruptibleRecv(uint8_t* data, size_t len, int timeout, c
}
if (interruptSocks5Recv)
return IntrRecvError::Interrupted;
- curTime = GetTimeMillis();
+ curTime = Now<SteadyMilliseconds>();
}
return len == 0 ? IntrRecvError::OK : IntrRecvError::Timeout;
}