Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/server.cpp
Show All 10 Lines | |||||
#include <shutdown.h> | #include <shutdown.h> | ||||
#include <sync.h> | #include <sync.h> | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
#include <boost/algorithm/string/classification.hpp> | #include <boost/algorithm/string/classification.hpp> | ||||
#include <boost/algorithm/string/split.hpp> | #include <boost/algorithm/string/split.hpp> | ||||
#include <boost/signals2/signal.hpp> | #include <boost/signals2/signal.hpp> | ||||
#include <cassert> | |||||
#include <memory> // for unique_ptr | #include <memory> // for unique_ptr | ||||
#include <mutex> | |||||
#include <set> | #include <set> | ||||
#include <unordered_map> | #include <unordered_map> | ||||
static RecursiveMutex cs_rpcWarmup; | static RecursiveMutex cs_rpcWarmup; | ||||
static std::atomic<bool> g_rpc_running{false}; | static std::atomic<bool> g_rpc_running{false}; | ||||
static std::once_flag g_rpc_interrupt_flag; | |||||
static std::once_flag g_rpc_stop_flag; | |||||
static bool fRPCInWarmup GUARDED_BY(cs_rpcWarmup) = true; | static bool fRPCInWarmup GUARDED_BY(cs_rpcWarmup) = true; | ||||
static std::string | static std::string | ||||
rpcWarmupStatus GUARDED_BY(cs_rpcWarmup) = "RPC server started"; | rpcWarmupStatus GUARDED_BY(cs_rpcWarmup) = "RPC server started"; | ||||
/* Timer-creating functions */ | /* Timer-creating functions */ | ||||
static RPCTimerInterface *timerInterface = nullptr; | static RPCTimerInterface *timerInterface = nullptr; | ||||
/* Map of name to timer. */ | /* Map of name to timer. */ | ||||
static Mutex g_deadline_timers_mutex; | static Mutex g_deadline_timers_mutex; | ||||
static std::map<std::string, std::unique_ptr<RPCTimerBase>> | static std::map<std::string, std::unique_ptr<RPCTimerBase>> | ||||
▲ Show 20 Lines • Show All 305 Lines • ▼ Show 20 Lines | |||||
void StartRPC() { | void StartRPC() { | ||||
LogPrint(BCLog::RPC, "Starting RPC\n"); | LogPrint(BCLog::RPC, "Starting RPC\n"); | ||||
g_rpc_running = true; | g_rpc_running = true; | ||||
g_rpcSignals.Started(); | g_rpcSignals.Started(); | ||||
} | } | ||||
void InterruptRPC() { | void InterruptRPC() { | ||||
// This function could be called twice if the GUI has been started with | |||||
// -server=1. | |||||
std::call_once(g_rpc_interrupt_flag, []() { | |||||
LogPrint(BCLog::RPC, "Interrupting RPC\n"); | LogPrint(BCLog::RPC, "Interrupting RPC\n"); | ||||
// Interrupt e.g. running longpolls | // Interrupt e.g. running longpolls | ||||
g_rpc_running = false; | g_rpc_running = false; | ||||
}); | |||||
} | } | ||||
void StopRPC() { | void StopRPC() { | ||||
// This function could be called twice if the GUI has been started with | |||||
// -server=1. | |||||
assert(!g_rpc_running); | |||||
std::call_once(g_rpc_stop_flag, []() { | |||||
LogPrint(BCLog::RPC, "Stopping RPC\n"); | LogPrint(BCLog::RPC, "Stopping RPC\n"); | ||||
WITH_LOCK(g_deadline_timers_mutex, deadlineTimers.clear()); | WITH_LOCK(g_deadline_timers_mutex, deadlineTimers.clear()); | ||||
DeleteAuthCookie(); | DeleteAuthCookie(); | ||||
g_rpcSignals.Stopped(); | g_rpcSignals.Stopped(); | ||||
}); | |||||
} | } | ||||
bool IsRPCRunning() { | bool IsRPCRunning() { | ||||
return g_rpc_running; | return g_rpc_running; | ||||
} | } | ||||
void RpcInterruptionPoint() { | void RpcInterruptionPoint() { | ||||
if (!IsRPCRunning()) { | if (!IsRPCRunning()) { | ||||
▲ Show 20 Lines • Show All 200 Lines • Show Last 20 Lines |