diff options
Diffstat (limited to 'Source/cmServer.cxx')
-rw-r--r-- | Source/cmServer.cxx | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/Source/cmServer.cxx b/Source/cmServer.cxx index c3e6811..f14e755 100644 --- a/Source/cmServer.cxx +++ b/Source/cmServer.cxx @@ -416,9 +416,18 @@ static void __start_thread(void* arg) server->Serve(&error); } +static void __shutdownThread(uv_async_t* arg) +{ + auto server = reinterpret_cast<cmServerBase*>(arg->data); + on_walk_to_shutdown(reinterpret_cast<uv_handle_t*>(arg), nullptr); + server->StartShutDown(); +} + bool cmServerBase::StartServeThread() { ServeThreadRunning = true; + uv_async_init(&Loop, &this->ShutdownSignal, __shutdownThread); + this->ShutdownSignal.data = this; uv_thread_create(&ServeThread, __start_thread, this); return true; } @@ -464,8 +473,6 @@ void cmServerBase::OnDisconnect() void cmServerBase::OnServeStart() { - uv_signal_start(&this->SIGINTHandler, &on_signal, SIGINT); - uv_signal_start(&this->SIGHUPHandler, &on_signal, SIGHUP); } void cmServerBase::StartShutDown() @@ -485,11 +492,7 @@ void cmServerBase::StartShutDown() } Connections.clear(); - uv_stop(&Loop); - uv_walk(&Loop, on_walk_to_shutdown, nullptr); - - uv_run(&Loop, UV_RUN_DEFAULT); } bool cmServerBase::OnSignal(int signum) @@ -503,12 +506,6 @@ cmServerBase::cmServerBase(cmConnection* connection) { uv_loop_init(&Loop); - uv_signal_init(&Loop, &this->SIGINTHandler); - uv_signal_init(&Loop, &this->SIGHUPHandler); - - this->SIGINTHandler.data = this; - this->SIGHUPHandler.data = this; - AddNewConnection(connection); } @@ -516,7 +513,7 @@ cmServerBase::~cmServerBase() { if (ServeThreadRunning) { - StartShutDown(); + uv_async_send(&this->ShutdownSignal); uv_thread_join(&ServeThread); } |