@@ -36,8 +36,8 @@ static Proxy nameProxy GUARDED_BY(g_proxyinfo_mutex);
36
36
int nConnectTimeout = DEFAULT_CONNECT_TIMEOUT;
37
37
bool fNameLookup = DEFAULT_NAME_LOOKUP;
38
38
39
- // Need ample time for negotiation for very slow proxies such as Tor (milliseconds)
40
- int g_socks5_recv_timeout = 20 * 1000 ;
39
+ // Need ample time for negotiation for very slow proxies such as Tor
40
+ std::chrono::milliseconds g_socks5_recv_timeout = 20s ;
41
41
static std::atomic<bool > interruptSocks5Recv (false );
42
42
43
43
std::vector<CNetAddr> WrappedGetAddrInfo (const std::string& name, bool allow_lookup)
@@ -296,7 +296,7 @@ enum class IntrRecvError {
296
296
*
297
297
* @param data The buffer where the read bytes should be stored.
298
298
* @param len The number of bytes to read into the specified buffer.
299
- * @param timeout The total timeout in milliseconds for this read.
299
+ * @param timeout The total timeout for this read.
300
300
* @param sock The socket (has to be in non-blocking mode) from which to read bytes.
301
301
*
302
302
* @returns An IntrRecvError indicating the resulting status of this read.
@@ -306,10 +306,10 @@ enum class IntrRecvError {
306
306
* @see This function can be interrupted by calling InterruptSocks5(bool).
307
307
* Sockets can be made non-blocking with Sock::SetNonBlocking().
308
308
*/
309
- static IntrRecvError InterruptibleRecv (uint8_t * data, size_t len, int timeout, const Sock& sock)
309
+ static IntrRecvError InterruptibleRecv (uint8_t * data, size_t len, std::chrono::milliseconds timeout, const Sock& sock)
310
310
{
311
- int64_t curTime = GetTimeMillis () ;
312
- int64_t endTime = curTime + timeout;
311
+ auto curTime{Now<SteadyMilliseconds>()} ;
312
+ const auto endTime{ curTime + timeout} ;
313
313
while (len > 0 && curTime < endTime) {
314
314
ssize_t ret = sock.Recv (data, len, 0 ); // Optimistically try the recv first
315
315
if (ret > 0 ) {
@@ -333,7 +333,7 @@ static IntrRecvError InterruptibleRecv(uint8_t* data, size_t len, int timeout, c
333
333
}
334
334
if (interruptSocks5Recv)
335
335
return IntrRecvError::Interrupted;
336
- curTime = GetTimeMillis ();
336
+ curTime = Now<SteadyMilliseconds> ();
337
337
}
338
338
return len == 0 ? IntrRecvError::OK : IntrRecvError::Timeout;
339
339
}
0 commit comments