Changeset View
Changeset View
Standalone View
Standalone View
src/httpserver.cpp
Show First 20 Lines • Show All 454 Lines • ▼ Show 20 Lines | #if LIBEVENT_VERSION_NUMBER >= 0x02010100 | ||||
} | } | ||||
return true; | return true; | ||||
#else | #else | ||||
// Can't update libevent logging if version < 02010100 | // Can't update libevent logging if version < 02010100 | ||||
return false; | return false; | ||||
#endif | #endif | ||||
} | } | ||||
static std::thread threadHTTP; | static std::thread g_thread_http; | ||||
static std::vector<std::thread> g_thread_http_workers; | static std::vector<std::thread> g_thread_http_workers; | ||||
void StartHTTPServer() { | void StartHTTPServer() { | ||||
LogPrint(BCLog::HTTP, "Starting HTTP server\n"); | LogPrint(BCLog::HTTP, "Starting HTTP server\n"); | ||||
int rpcThreads = | int rpcThreads = | ||||
std::max((long)gArgs.GetArg("-rpcthreads", DEFAULT_HTTP_THREADS), 1L); | std::max((long)gArgs.GetArg("-rpcthreads", DEFAULT_HTTP_THREADS), 1L); | ||||
LogPrintf("HTTP: starting %d worker threads\n", rpcThreads); | LogPrintf("HTTP: starting %d worker threads\n", rpcThreads); | ||||
threadHTTP = std::thread(ThreadHTTP, eventBase); | g_thread_http = std::thread(ThreadHTTP, eventBase); | ||||
for (int i = 0; i < rpcThreads; i++) { | for (int i = 0; i < rpcThreads; i++) { | ||||
g_thread_http_workers.emplace_back(HTTPWorkQueueRun, workQueue, i); | g_thread_http_workers.emplace_back(HTTPWorkQueueRun, workQueue, i); | ||||
} | } | ||||
} | } | ||||
void InterruptHTTPServer() { | void InterruptHTTPServer() { | ||||
LogPrint(BCLog::HTTP, "Interrupting HTTP server\n"); | LogPrint(BCLog::HTTP, "Interrupting HTTP server\n"); | ||||
Show All 20 Lines | void StopHTTPServer() { | ||||
// Unlisten sockets, these are what make the event loop running, which means | // Unlisten sockets, these are what make the event loop running, which means | ||||
// that after this and all connections are closed the event loop will quit. | // that after this and all connections are closed the event loop will quit. | ||||
for (evhttp_bound_socket *socket : boundSockets) { | for (evhttp_bound_socket *socket : boundSockets) { | ||||
evhttp_del_accept_socket(eventHTTP, socket); | evhttp_del_accept_socket(eventHTTP, socket); | ||||
} | } | ||||
boundSockets.clear(); | boundSockets.clear(); | ||||
if (eventBase) { | if (eventBase) { | ||||
LogPrint(BCLog::HTTP, "Waiting for HTTP event thread to exit\n"); | LogPrint(BCLog::HTTP, "Waiting for HTTP event thread to exit\n"); | ||||
threadHTTP.join(); | if (g_thread_http.joinable()) { | ||||
g_thread_http.join(); | |||||
} | |||||
} | } | ||||
if (eventHTTP) { | if (eventHTTP) { | ||||
evhttp_free(eventHTTP); | evhttp_free(eventHTTP); | ||||
eventHTTP = nullptr; | eventHTTP = nullptr; | ||||
} | } | ||||
if (eventBase) { | if (eventBase) { | ||||
event_base_free(eventBase); | event_base_free(eventBase); | ||||
eventBase = nullptr; | eventBase = nullptr; | ||||
▲ Show 20 Lines • Show All 181 Lines • Show Last 20 Lines |