diff options
author | Jon Atack <jon@atack.com> | 2022-05-17 14:46:13 +0200 |
---|---|---|
committer | Jon Atack <jon@atack.com> | 2022-05-17 16:56:50 +0200 |
commit | 3a998d2e37bf76667b08cd947807ada1305520d7 (patch) | |
tree | 7e41f07e48d6785b5b88cbf7c4602fc92de39c25 /src/bitcoin-cli.cpp | |
parent | 3799d2dcdd736dd24850b192e1b264bee1cd5e5a (diff) |
Use steady_clock in ConnectAndCallRPC and inline time call in loop conditional
to avoid unnecessary invocations and an unneeded local variable allocation.
Diffstat (limited to 'src/bitcoin-cli.cpp')
-rw-r--r-- | src/bitcoin-cli.cpp | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index fd2e09542f..640643a695 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -844,7 +844,7 @@ static UniValue ConnectAndCallRPC(BaseRequestHandler* rh, const std::string& str // Execute and handle connection failures with -rpcwait. const bool fWait = gArgs.GetBoolArg("-rpcwait", false); const int timeout = gArgs.GetIntArg("-rpcwaittimeout", DEFAULT_WAIT_CLIENT_TIMEOUT); - const auto deadline{GetTime<std::chrono::microseconds>() + 1s * timeout}; + const auto deadline{std::chrono::steady_clock::now() + 1s * timeout}; do { try { @@ -857,8 +857,7 @@ static UniValue ConnectAndCallRPC(BaseRequestHandler* rh, const std::string& str } break; // Connection succeeded, no need to retry. } catch (const CConnectionFailed& e) { - const auto now{GetTime<std::chrono::microseconds>()}; - if (fWait && (timeout <= 0 || now < deadline)) { + if (fWait && (timeout <= 0 || std::chrono::steady_clock::now() < deadline)) { UninterruptibleSleep(1s); } else { throw CConnectionFailed(strprintf("timeout on transient error: %s", e.what())); |