|
15 | 15 | #include <netbase.h> |
16 | 16 | #include <node/interface_ui.h> |
17 | 17 | #include <rpc/protocol.h> // For HTTP status codes |
18 | | -#include <shutdown.h> |
19 | 18 | #include <sync.h> |
20 | 19 | #include <util/check.h> |
| 20 | +#include <util/signalinterrupt.h> |
21 | 21 | #include <util/strencodings.h> |
22 | 22 | #include <util/threadnames.h> |
23 | 23 | #include <util/translation.h> |
@@ -284,7 +284,7 @@ static void http_request_cb(struct evhttp_request* req, void* arg) |
284 | 284 | } |
285 | 285 | } |
286 | 286 | } |
287 | | - std::unique_ptr<HTTPRequest> hreq(new HTTPRequest(req)); |
| 287 | + auto hreq{std::make_unique<HTTPRequest>(req, *static_cast<const util::SignalInterrupt*>(arg))}; |
288 | 288 |
|
289 | 289 | // Early address-based allow check |
290 | 290 | if (!ClientAllowed(hreq->GetPeer())) { |
@@ -425,7 +425,7 @@ static void libevent_log_cb(int severity, const char *msg) |
425 | 425 | LogPrintLevel(BCLog::LIBEVENT, level, "%s\n", msg); |
426 | 426 | } |
427 | 427 |
|
428 | | -bool InitHTTPServer() |
| 428 | +bool InitHTTPServer(const util::SignalInterrupt& interrupt) |
429 | 429 | { |
430 | 430 | if (!InitHTTPAllowList()) |
431 | 431 | return false; |
@@ -454,7 +454,7 @@ bool InitHTTPServer() |
454 | 454 | evhttp_set_timeout(http, gArgs.GetIntArg("-rpcservertimeout", DEFAULT_HTTP_SERVER_TIMEOUT)); |
455 | 455 | evhttp_set_max_headers_size(http, MAX_HEADERS_SIZE); |
456 | 456 | evhttp_set_max_body_size(http, MAX_SIZE); |
457 | | - evhttp_set_gencb(http, http_request_cb, nullptr); |
| 457 | + evhttp_set_gencb(http, http_request_cb, (void*)&interrupt); |
458 | 458 |
|
459 | 459 | if (!HTTPBindAddresses(http)) { |
460 | 460 | LogPrintf("Unable to bind any endpoint for RPC server\n"); |
@@ -579,7 +579,8 @@ void HTTPEvent::trigger(struct timeval* tv) |
579 | 579 | else |
580 | 580 | evtimer_add(ev, tv); // trigger after timeval passed |
581 | 581 | } |
582 | | -HTTPRequest::HTTPRequest(struct evhttp_request* _req, bool _replySent) : req(_req), replySent(_replySent) |
| 582 | +HTTPRequest::HTTPRequest(struct evhttp_request* _req, const util::SignalInterrupt& interrupt, bool _replySent) |
| 583 | + : req(_req), m_interrupt(interrupt), replySent(_replySent) |
583 | 584 | { |
584 | 585 | } |
585 | 586 |
|
@@ -639,7 +640,7 @@ void HTTPRequest::WriteHeader(const std::string& hdr, const std::string& value) |
639 | 640 | void HTTPRequest::WriteReply(int nStatus, const std::string& strReply) |
640 | 641 | { |
641 | 642 | assert(!replySent && req); |
642 | | - if (ShutdownRequested()) { |
| 643 | + if (m_interrupt) { |
643 | 644 | WriteHeader("Connection", "close"); |
644 | 645 | } |
645 | 646 | // Send event to main http thread to send reply message |
|
0 commit comments