diff options
author | Vasil Dimov <vd@FreeBSD.org> | 2020-12-23 16:40:11 +0100 |
---|---|---|
committer | Vasil Dimov <vd@FreeBSD.org> | 2021-02-10 13:30:08 +0100 |
commit | ba9d73268f9585d4b9254adcf54708f88222798b (patch) | |
tree | 7817023a5deab6c4bcb0de90b748e49dc026f1ab /src/util/time.h | |
parent | dec9b5e850c6aad989e814aea5b630b36f55d580 (diff) | |
download | bitcoin-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.h')
-rw-r--r-- | src/util/time.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/util/time.h b/src/util/time.h index 2c0e3d83f6..03b75b5be5 100644 --- a/src/util/time.h +++ b/src/util/time.h @@ -27,6 +27,7 @@ void UninterruptibleSleep(const std::chrono::microseconds& n); * interface that doesn't support std::chrono (e.g. RPC, debug log, or the GUI) */ inline int64_t count_seconds(std::chrono::seconds t) { return t.count(); } +inline int64_t count_milliseconds(std::chrono::milliseconds t) { return t.count(); } inline int64_t count_microseconds(std::chrono::microseconds t) { return t.count(); } /** @@ -64,4 +65,9 @@ int64_t ParseISO8601DateTime(const std::string& str); */ struct timeval MillisToTimeval(int64_t nTimeout); +/** + * Convert milliseconds to a struct timeval for e.g. select. + */ +struct timeval MillisToTimeval(std::chrono::milliseconds ms); + #endif // BITCOIN_UTIL_TIME_H |