Skip to content

Commit 59b2047

Browse files
committed
Refactor http server module for consideration of a potential core dump
1 parent 056f73a commit 59b2047

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

sentinel-core/transport/command/http_server.cc

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ namespace Transport {
1111
HttpServer::HttpServer(http_request_callback_t callback)
1212
: request_callback_(callback) {}
1313

14-
HttpServer::~HttpServer() {
15-
if (http_) {
16-
evhttp_free(http_);
17-
http_ = nullptr;
18-
}
19-
}
14+
HttpServer::~HttpServer() { Stop(); }
2015

2116
bool HttpServer::Start(int port) {
2217
auto ret = event_loop_thread_.Start();
@@ -26,11 +21,9 @@ bool HttpServer::Start(int port) {
2621

2722
port_ = port;
2823

29-
std::promise<bool> start_promise;
30-
auto start_future = start_promise.get_future();
31-
auto task = [&start_promise, this]() { InternalStart(start_promise); };
32-
33-
event_loop_thread_.RunTask(task);
24+
auto start_future = start_promise_.get_future();
25+
event_loop_thread_.RunTask(
26+
[this](void) mutable { InternalStart(start_promise_); });
3427

3528
return start_future.get();
3629
}

sentinel-core/transport/command/http_server.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class HttpServer {
3333

3434
struct evhttp *http_ = nullptr;
3535
http_request_callback_t request_callback_;
36+
std::promise<bool> start_promise_;
3637

3738
static void HttpGenCallback(struct evhttp_request *req, void *arg);
3839

sentinel-core/transport/common/event_loop_thread.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ bool EventLoopThread::Start() {
2020
}
2121

2222
void EventLoopThread::Stop() {
23-
if (stoped_.load()) {
23+
bool expected = false;
24+
if (!stoped_.compare_exchange_strong(expected, true)) {
2425
return;
2526
}
2627

27-
stoped_ = true;
28-
2928
Wakeup();
3029

3130
thd_->join();

0 commit comments

Comments
 (0)