mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-29 18:20:58 +02:00
Use steady_clock in ConnectAndCallRPC and inline time call in loop conditional
to avoid unnecessary invocations and an unneeded local variable allocation.
This commit is contained in:
@ -844,7 +844,7 @@ static UniValue ConnectAndCallRPC(BaseRequestHandler* rh, const std::string& str
|
|||||||
// Execute and handle connection failures with -rpcwait.
|
// Execute and handle connection failures with -rpcwait.
|
||||||
const bool fWait = gArgs.GetBoolArg("-rpcwait", false);
|
const bool fWait = gArgs.GetBoolArg("-rpcwait", false);
|
||||||
const int timeout = gArgs.GetIntArg("-rpcwaittimeout", DEFAULT_WAIT_CLIENT_TIMEOUT);
|
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 {
|
do {
|
||||||
try {
|
try {
|
||||||
@ -857,8 +857,7 @@ static UniValue ConnectAndCallRPC(BaseRequestHandler* rh, const std::string& str
|
|||||||
}
|
}
|
||||||
break; // Connection succeeded, no need to retry.
|
break; // Connection succeeded, no need to retry.
|
||||||
} catch (const CConnectionFailed& e) {
|
} catch (const CConnectionFailed& e) {
|
||||||
const auto now{GetTime<std::chrono::microseconds>()};
|
if (fWait && (timeout <= 0 || std::chrono::steady_clock::now() < deadline)) {
|
||||||
if (fWait && (timeout <= 0 || now < deadline)) {
|
|
||||||
UninterruptibleSleep(1s);
|
UninterruptibleSleep(1s);
|
||||||
} else {
|
} else {
|
||||||
throw CConnectionFailed(strprintf("timeout on transient error: %s", e.what()));
|
throw CConnectionFailed(strprintf("timeout on transient error: %s", e.what()));
|
||||||
|
Reference in New Issue
Block a user