aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorVasil Dimov <vd@FreeBSD.org>2021-01-04 13:14:32 +0100
committerVasil Dimov <vd@FreeBSD.org>2021-02-10 11:00:12 +0100
commitaa17a44551c03b00a47854438afe9f2f89b6ea74 (patch)
tree32818a531a860f31a2ada1ae8fdef4341cc5296f /src/util
parent29d2aeb4a2b1830be4724aab3a84a62f072056f4 (diff)
net: move MillisToTimeval() from netbase to util/time
Move `MillisToTimeval()` from `netbase.{h,cpp}` to `src/util/system.{h,cpp}`. This is necessary in order to use `MillisToTimeval()` from a newly introduced `src/util/sock.{h,cpp}` which cannot depend on netbase because netbase will depend on it.
Diffstat (limited to 'src/util')
-rw-r--r--src/util/time.cpp9
-rw-r--r--src/util/time.h7
2 files changed, 16 insertions, 0 deletions
diff --git a/src/util/time.cpp b/src/util/time.cpp
index e96972fe12..4da041e5a5 100644
--- a/src/util/time.cpp
+++ b/src/util/time.cpp
@@ -7,6 +7,7 @@
#include <config/bitcoin-config.h>
#endif
+#include <compat.h>
#include <util/time.h>
#include <atomic>
@@ -114,3 +115,11 @@ int64_t ParseISO8601DateTime(const std::string& str)
return 0;
return (ptime - epoch).total_seconds();
}
+
+struct timeval MillisToTimeval(int64_t nTimeout)
+{
+ struct timeval timeout;
+ timeout.tv_sec = nTimeout / 1000;
+ timeout.tv_usec = (nTimeout % 1000) * 1000;
+ return timeout;
+}
diff --git a/src/util/time.h b/src/util/time.h
index c69f604dc6..2c0e3d83f6 100644
--- a/src/util/time.h
+++ b/src/util/time.h
@@ -6,6 +6,8 @@
#ifndef BITCOIN_UTIL_TIME_H
#define BITCOIN_UTIL_TIME_H
+#include <compat.h>
+
#include <chrono>
#include <stdint.h>
#include <string>
@@ -57,4 +59,9 @@ std::string FormatISO8601DateTime(int64_t nTime);
std::string FormatISO8601Date(int64_t nTime);
int64_t ParseISO8601DateTime(const std::string& str);
+/**
+ * Convert milliseconds to a struct timeval for e.g. select.
+ */
+struct timeval MillisToTimeval(int64_t nTimeout);
+
#endif // BITCOIN_UTIL_TIME_H