mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-13 11:40:42 +02:00
Merge bitcoin/bitcoin#22361: refactor: Make httpserver work queue a unique_ptr
fa92e60f38
refactor: Make httpserver work queue a unique_ptr (MarcoFalke) Pull request description: This simplifies the code a bit because `if (p) { delete p; p = nullptr; }` can be replaced by a call to the `reset()` member. ACKs for top commit: promag: Core review ACKfa92e60f38
. jonatack: ACKfa92e60f38
code review, debug build clean, ran test/functional/interface*.py tests locally as a sanity check hebasto: ACKfa92e60f38
, I have reviewed the code and it looks OK, I agree it can be merged. Tree-SHA512: 6b122162317dd4ad6889341745c7ac1903a3ee510f6548f46dc356308442a6eff13eb8dc604c38ba18783e7a66d2b836d641a8594ff980a010c12c97f3856684
This commit is contained in:
commit
a000cb013c
@ -136,7 +136,7 @@ static struct evhttp* eventHTTP = nullptr;
|
|||||||
//! List of subnets to allow RPC connections from
|
//! List of subnets to allow RPC connections from
|
||||||
static std::vector<CSubNet> rpc_allow_subnets;
|
static std::vector<CSubNet> rpc_allow_subnets;
|
||||||
//! Work queue for handling longer requests off the event loop thread
|
//! Work queue for handling longer requests off the event loop thread
|
||||||
static WorkQueue<HTTPClosure>* workQueue = nullptr;
|
static std::unique_ptr<WorkQueue<HTTPClosure>> g_work_queue{nullptr};
|
||||||
//! Handlers for (sub)paths
|
//! Handlers for (sub)paths
|
||||||
static std::vector<HTTPPathHandler> pathHandlers;
|
static std::vector<HTTPPathHandler> pathHandlers;
|
||||||
//! Bound listening sockets
|
//! Bound listening sockets
|
||||||
@ -256,10 +256,10 @@ static void http_request_cb(struct evhttp_request* req, void* arg)
|
|||||||
// Dispatch to worker thread
|
// Dispatch to worker thread
|
||||||
if (i != iend) {
|
if (i != iend) {
|
||||||
std::unique_ptr<HTTPWorkItem> item(new HTTPWorkItem(std::move(hreq), path, i->handler));
|
std::unique_ptr<HTTPWorkItem> item(new HTTPWorkItem(std::move(hreq), path, i->handler));
|
||||||
assert(workQueue);
|
assert(g_work_queue);
|
||||||
if (workQueue->Enqueue(item.get()))
|
if (g_work_queue->Enqueue(item.get())) {
|
||||||
item.release(); /* if true, queue took ownership */
|
item.release(); /* if true, queue took ownership */
|
||||||
else {
|
} else {
|
||||||
LogPrintf("WARNING: request rejected because http work queue depth exceeded, it can be increased with the -rpcworkqueue= setting\n");
|
LogPrintf("WARNING: request rejected because http work queue depth exceeded, it can be increased with the -rpcworkqueue= setting\n");
|
||||||
item->req->WriteReply(HTTP_SERVICE_UNAVAILABLE, "Work queue depth exceeded");
|
item->req->WriteReply(HTTP_SERVICE_UNAVAILABLE, "Work queue depth exceeded");
|
||||||
}
|
}
|
||||||
@ -392,7 +392,7 @@ bool InitHTTPServer()
|
|||||||
int workQueueDepth = std::max((long)gArgs.GetArg("-rpcworkqueue", DEFAULT_HTTP_WORKQUEUE), 1L);
|
int workQueueDepth = std::max((long)gArgs.GetArg("-rpcworkqueue", DEFAULT_HTTP_WORKQUEUE), 1L);
|
||||||
LogPrintf("HTTP: creating work queue of depth %d\n", workQueueDepth);
|
LogPrintf("HTTP: creating work queue of depth %d\n", workQueueDepth);
|
||||||
|
|
||||||
workQueue = new WorkQueue<HTTPClosure>(workQueueDepth);
|
g_work_queue = std::make_unique<WorkQueue<HTTPClosure>>(workQueueDepth);
|
||||||
// transfer ownership to eventBase/HTTP via .release()
|
// transfer ownership to eventBase/HTTP via .release()
|
||||||
eventBase = base_ctr.release();
|
eventBase = base_ctr.release();
|
||||||
eventHTTP = http_ctr.release();
|
eventHTTP = http_ctr.release();
|
||||||
@ -424,7 +424,7 @@ void StartHTTPServer()
|
|||||||
g_thread_http = 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, g_work_queue.get(), i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -435,14 +435,15 @@ void InterruptHTTPServer()
|
|||||||
// Reject requests on current connections
|
// Reject requests on current connections
|
||||||
evhttp_set_gencb(eventHTTP, http_reject_request_cb, nullptr);
|
evhttp_set_gencb(eventHTTP, http_reject_request_cb, nullptr);
|
||||||
}
|
}
|
||||||
if (workQueue)
|
if (g_work_queue) {
|
||||||
workQueue->Interrupt();
|
g_work_queue->Interrupt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StopHTTPServer()
|
void StopHTTPServer()
|
||||||
{
|
{
|
||||||
LogPrint(BCLog::HTTP, "Stopping HTTP server\n");
|
LogPrint(BCLog::HTTP, "Stopping HTTP server\n");
|
||||||
if (workQueue) {
|
if (g_work_queue) {
|
||||||
LogPrint(BCLog::HTTP, "Waiting for HTTP worker threads to exit\n");
|
LogPrint(BCLog::HTTP, "Waiting for HTTP worker threads to exit\n");
|
||||||
for (auto& thread : g_thread_http_workers) {
|
for (auto& thread : g_thread_http_workers) {
|
||||||
thread.join();
|
thread.join();
|
||||||
@ -467,10 +468,7 @@ void StopHTTPServer()
|
|||||||
event_base_free(eventBase);
|
event_base_free(eventBase);
|
||||||
eventBase = nullptr;
|
eventBase = nullptr;
|
||||||
}
|
}
|
||||||
if (workQueue) {
|
g_work_queue.reset();
|
||||||
delete workQueue;
|
|
||||||
workQueue = nullptr;
|
|
||||||
}
|
|
||||||
LogPrint(BCLog::HTTP, "Stopped HTTP server\n");
|
LogPrint(BCLog::HTTP, "Stopped HTTP server\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user