MCPcopy Create free account
hub / github.com/LUX-Core/lux / StopHTTPServer

Function StopHTTPServer

src/httpserver.cpp:459–495  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

457
458
459void StopHTTPServer()
460{
461 LogPrint("http", "Stopping HTTP server\n");
462 if (workQueue) {
463 LogPrint("http", "Waiting for HTTP worker threads to exit\n");
464 for (auto& thread: g_thread_http_workers) {
465 thread.join();
466 }
467 g_thread_http_workers.clear();
468 delete workQueue;
469 workQueue = nullptr;
470 }
471 if (eventBase) {
472 LogPrint("http", "Waiting for HTTP event thread to exit\n");
473 event_base_loopexit(eventBase, nullptr);
474 // Give event loop a few seconds to exit (to send back last RPC responses), then break it
475 // Before this was solved with event_base_loopexit, but that didn't work as expected in
476 // at least libevent 2.0.21 and always introduced a delay. In libevent
477 // master that appears to be solved, so in the future that solution
478 // could be used again (if desirable).
479 // (see discussion in https://github.com/bitcoin/bitcoin/pull/6990)
480 if (threadResult.valid() && threadResult.wait_for(std::chrono::milliseconds(2000)) == std::future_status::timeout) {
481 LogPrintf("HTTP event loop did not exit within allotted time, sending loopbreak\n");
482 event_base_loopbreak(eventBase);
483 }
484 threadHTTP.join();
485 }
486 if (eventHTTP) {
487 evhttp_free(eventHTTP);
488 eventHTTP = nullptr;
489 }
490 if (eventBase) {
491 event_base_free(eventBase);
492 eventBase = nullptr;
493 }
494 LogPrint("http", "Stopped HTTP server\n");
495}
496
497struct event_base* EventBase()
498{

Callers 1

PrepareShutdownFunction · 0.85

Calls 5

LogPrintFunction · 0.85
validMethod · 0.80
joinMethod · 0.45
clearMethod · 0.45
wait_forMethod · 0.45

Tested by

no test coverage detected