@@ -36,8 +36,8 @@ static Proxy nameProxy GUARDED_BY(g_proxyinfo_mutex);
3636int nConnectTimeout = DEFAULT_CONNECT_TIMEOUT;
3737bool fNameLookup = DEFAULT_NAME_LOOKUP;
3838
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 ;
4141static std::atomic<bool > interruptSocks5Recv (false );
4242
4343std::vector<CNetAddr> WrappedGetAddrInfo (const std::string& name, bool allow_lookup)
@@ -296,7 +296,7 @@ enum class IntrRecvError {
296296 *
297297 * @param data The buffer where the read bytes should be stored.
298298 * @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.
300300 * @param sock The socket (has to be in non-blocking mode) from which to read bytes.
301301 *
302302 * @returns An IntrRecvError indicating the resulting status of this read.
@@ -306,10 +306,10 @@ enum class IntrRecvError {
306306 * @see This function can be interrupted by calling InterruptSocks5(bool).
307307 * Sockets can be made non-blocking with Sock::SetNonBlocking().
308308 */
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)
310310{
311- int64_t curTime = GetTimeMillis () ;
312- int64_t endTime = curTime + timeout;
311+ auto curTime{Now<SteadyMilliseconds>()} ;
312+ const auto endTime{ curTime + timeout} ;
313313 while (len > 0 && curTime < endTime) {
314314 ssize_t ret = sock.Recv (data, len, 0 ); // Optimistically try the recv first
315315 if (ret > 0 ) {
@@ -333,7 +333,7 @@ static IntrRecvError InterruptibleRecv(uint8_t* data, size_t len, int timeout, c
333333 }
334334 if (interruptSocks5Recv)
335335 return IntrRecvError::Interrupted;
336- curTime = GetTimeMillis ();
336+ curTime = Now<SteadyMilliseconds> ();
337337 }
338338 return len == 0 ? IntrRecvError::OK : IntrRecvError::Timeout;
339339}
0 commit comments