Changeset View
Changeset View
Standalone View
Standalone View
src/bitcoin-cli.cpp
Show First 20 Lines • Show All 377 Lines • ▼ Show 20 Lines | static UniValue CallRPC(BaseRequestHandler *rh, const std::string &strMethod, | ||||
port = gArgs.GetArg("-rpcport", port); | port = gArgs.GetArg("-rpcport", port); | ||||
// Obtain event base | // Obtain event base | ||||
raii_event_base base = obtain_event_base(); | raii_event_base base = obtain_event_base(); | ||||
// Synchronously look up hostname | // Synchronously look up hostname | ||||
raii_evhttp_connection evcon = | raii_evhttp_connection evcon = | ||||
obtain_evhttp_connection_base(base.get(), host, port); | obtain_evhttp_connection_base(base.get(), host, port); | ||||
evhttp_connection_set_timeout( | |||||
evcon.get(), | // Set connection timeout | ||||
gArgs.GetArg("-rpcclienttimeout", DEFAULT_HTTP_CLIENT_TIMEOUT)); | { | ||||
const int timeout = | |||||
gArgs.GetArg("-rpcclienttimeout", DEFAULT_HTTP_CLIENT_TIMEOUT); | |||||
if (timeout > 0) { | |||||
evhttp_connection_set_timeout(evcon.get(), timeout); | |||||
} else { | |||||
// Indefinite request timeouts are not possible in libevent-http, | |||||
// so we set the timeout to a very long time period instead. | |||||
// Average length of year in Gregorian calendar | |||||
constexpr int YEAR_IN_SECONDS = 31556952; | |||||
evhttp_connection_set_timeout(evcon.get(), 5 * YEAR_IN_SECONDS); | |||||
} | |||||
} | |||||
HTTPReply response; | HTTPReply response; | ||||
raii_evhttp_request req = | raii_evhttp_request req = | ||||
obtain_evhttp_request(http_request_done, (void *)&response); | obtain_evhttp_request(http_request_done, (void *)&response); | ||||
if (req == nullptr) { | if (req == nullptr) { | ||||
throw std::runtime_error("create http request failed"); | throw std::runtime_error("create http request failed"); | ||||
} | } | ||||
#if LIBEVENT_VERSION_NUMBER >= 0x02010300 | #if LIBEVENT_VERSION_NUMBER >= 0x02010300 | ||||
▲ Show 20 Lines • Show All 251 Lines • Show Last 20 Lines |