File tree Expand file tree Collapse file tree 3 files changed +7
-14
lines changed Expand file tree Collapse file tree 3 files changed +7
-14
lines changed Original file line number Diff line number Diff line change @@ -11,12 +11,7 @@ namespace Transport {
1111HttpServer::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
2116bool 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}
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -20,12 +20,11 @@ bool EventLoopThread::Start() {
2020}
2121
2222void 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 ();
You can’t perform that action at this time.
0 commit comments