Skip to content

Commit aa17a44

Browse files
committed
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.
1 parent 29d2aeb commit aa17a44

File tree

5 files changed

+18
-12
lines changed

5 files changed

+18
-12
lines changed

src/netbase.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <util/strencodings.h>
1111
#include <util/string.h>
1212
#include <util/system.h>
13+
#include <util/time.h>
1314

1415
#include <atomic>
1516
#include <cstdint>
@@ -271,14 +272,6 @@ CService LookupNumeric(const std::string& name, int portDefault)
271272
return addr;
272273
}
273274

274-
struct timeval MillisToTimeval(int64_t nTimeout)
275-
{
276-
struct timeval timeout;
277-
timeout.tv_sec = nTimeout / 1000;
278-
timeout.tv_usec = (nTimeout % 1000) * 1000;
279-
return timeout;
280-
}
281-
282275
/** SOCKS version */
283276
enum SOCKSVersion: uint8_t {
284277
SOCKS4 = 0x04,

src/netbase.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ bool CloseSocket(SOCKET& hSocket);
6262
bool SetSocketNonBlocking(const SOCKET& hSocket, bool fNonBlocking);
6363
/** Set the TCP_NODELAY flag on a socket */
6464
bool SetSocketNoDelay(const SOCKET& hSocket);
65-
/**
66-
* Convert milliseconds to a struct timeval for e.g. select.
67-
*/
68-
struct timeval MillisToTimeval(int64_t nTimeout);
6965
void InterruptSocks5(bool interrupt);
7066

7167
#endif // BITCOIN_NETBASE_H

src/torcontrol.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <netbase.h>
1515
#include <util/strencodings.h>
1616
#include <util/system.h>
17+
#include <util/time.h>
1718

1819
#include <vector>
1920
#include <deque>

src/util/time.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <config/bitcoin-config.h>
88
#endif
99

10+
#include <compat.h>
1011
#include <util/time.h>
1112

1213
#include <atomic>
@@ -114,3 +115,11 @@ int64_t ParseISO8601DateTime(const std::string& str)
114115
return 0;
115116
return (ptime - epoch).total_seconds();
116117
}
118+
119+
struct timeval MillisToTimeval(int64_t nTimeout)
120+
{
121+
struct timeval timeout;
122+
timeout.tv_sec = nTimeout / 1000;
123+
timeout.tv_usec = (nTimeout % 1000) * 1000;
124+
return timeout;
125+
}

src/util/time.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#ifndef BITCOIN_UTIL_TIME_H
77
#define BITCOIN_UTIL_TIME_H
88

9+
#include <compat.h>
10+
911
#include <chrono>
1012
#include <stdint.h>
1113
#include <string>
@@ -57,4 +59,9 @@ std::string FormatISO8601DateTime(int64_t nTime);
5759
std::string FormatISO8601Date(int64_t nTime);
5860
int64_t ParseISO8601DateTime(const std::string& str);
5961

62+
/**
63+
* Convert milliseconds to a struct timeval for e.g. select.
64+
*/
65+
struct timeval MillisToTimeval(int64_t nTimeout);
66+
6067
#endif // BITCOIN_UTIL_TIME_H

0 commit comments

Comments
 (0)