From 838e05521e4ad0e65eb9db307661d16bebed277c Mon Sep 17 00:00:00 2001 From: Koncord Date: Wed, 13 Sep 2017 17:56:38 +0800 Subject: [PATCH] [Master] Minor fixes --- apps/master/AdminRest.cpp | 4 +++- apps/master/AdminRest.hpp | 1 + apps/master/RestServer.cpp | 4 +++- apps/master/RestServer.hpp | 1 + apps/master/main.cpp | 8 ++------ 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/apps/master/AdminRest.cpp b/apps/master/AdminRest.cpp index 74b93e46d..5afab2b00 100644 --- a/apps/master/AdminRest.cpp +++ b/apps/master/AdminRest.cpp @@ -58,10 +58,12 @@ void AdminRest::start() *response << response400; }; - httpServer.start(); + thr = thread([this](){httpServer.start();}); } void AdminRest::stop() { httpServer.stop(); + if(thr.joinable()) + thr.join(); } diff --git a/apps/master/AdminRest.hpp b/apps/master/AdminRest.hpp index 26a853f45..6705051a2 100644 --- a/apps/master/AdminRest.hpp +++ b/apps/master/AdminRest.hpp @@ -19,6 +19,7 @@ public: private: HttpsServer httpServer; std::shared_ptr master; + std::thread thr; }; diff --git a/apps/master/RestServer.cpp b/apps/master/RestServer.cpp index 58cb31ed9..726a3a47a 100644 --- a/apps/master/RestServer.cpp +++ b/apps/master/RestServer.cpp @@ -167,7 +167,7 @@ void RestServer::start() *response << response400; }; - httpServer.start(); + thr = thread([this](){httpServer.start();}); } void RestServer::cacheUpdated() @@ -178,4 +178,6 @@ void RestServer::cacheUpdated() void RestServer::stop() { httpServer.stop(); + if(thr.joinable()) + thr.join(); } diff --git a/apps/master/RestServer.hpp b/apps/master/RestServer.hpp index 1107660cf..3b52ebb6a 100644 --- a/apps/master/RestServer.hpp +++ b/apps/master/RestServer.hpp @@ -24,6 +24,7 @@ private: HttpServer httpServer; MasterServer::ServerMap *serverMap; bool updatedCache = true; + std::thread thr; }; diff --git a/apps/master/main.cpp b/apps/master/main.cpp index 0639f3872..938e379a2 100644 --- a/apps/master/main.cpp +++ b/apps/master/main.cpp @@ -67,12 +67,8 @@ int main(int argc, char* argv[]) signal(SIGTERM, onExit); masterServer->Start(); - - thread rest_thread([]() { restServer->start();}); - thread restAdmin_thread([]() { restAdminServer->start();}); - - rest_thread.join(); - restAdmin_thread.join(); + restServer->start(); + restAdminServer->start(); masterServer->Wait(); return 0;