aboutsummaryrefslogtreecommitdiff
path: root/src/util/time.cpp
diff options
context:
space:
mode:
authorVasil Dimov <vd@FreeBSD.org>2020-12-23 16:40:11 +0100
committerVasil Dimov <vd@FreeBSD.org>2021-02-10 13:30:08 +0100
commitba9d73268f9585d4b9254adcf54708f88222798b (patch)
tree7817023a5deab6c4bcb0de90b748e49dc026f1ab /src/util/time.cpp
parentdec9b5e850c6aad989e814aea5b630b36f55d580 (diff)
downloadbitcoin-ba9d73268f9585d4b9254adcf54708f88222798b.tar.xz
net: add RAII socket and use it instead of bare SOCKET
Introduce a class to manage the lifetime of a socket - when the object that contains the socket goes out of scope, the underlying socket will be closed. In addition, the new `Sock` class has a `Send()`, `Recv()` and `Wait()` methods that can be overridden by unit tests to mock the socket operations. The `Wait()` method also hides the `#ifdef USE_POLL poll() #else select() #endif` technique from higher level code.
Diffstat (limited to 'src/util/time.cpp')
-rw-r--r--src/util/time.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/util/time.cpp b/src/util/time.cpp
index 4da041e5a5..4aed9f60b0 100644
--- a/src/util/time.cpp
+++ b/src/util/time.cpp
@@ -123,3 +123,8 @@ struct timeval MillisToTimeval(int64_t nTimeout)
timeout.tv_usec = (nTimeout % 1000) * 1000;
return timeout;
}
+
+struct timeval MillisToTimeval(std::chrono::milliseconds ms)
+{
+ return MillisToTimeval(count_milliseconds(ms));
+}