summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/cmConnection.cxx5
-rw-r--r--Source/cmConnection.h7
-rw-r--r--Source/cmPipeConnection.cxx13
-rw-r--r--Source/cmServer.cxx23
-rw-r--r--Source/cmServer.h1
-rw-r--r--Source/cmServerConnection.cxx8
6 files changed, 29 insertions, 28 deletions
diff --git a/Source/cmConnection.cxx b/Source/cmConnection.cxx
index f3fc1ef..bc29e41 100644
--- a/Source/cmConnection.cxx
+++ b/Source/cmConnection.cxx
@@ -38,11 +38,6 @@ void cmEventBasedConnection::on_read(uv_stream_t* stream, ssize_t nread,
delete[](buf->base);
}
-void cmEventBasedConnection::on_close_delete(uv_handle_t* handle)
-{
- delete handle;
-}
-
void cmEventBasedConnection::on_close(uv_handle_t* /*handle*/)
{
}
diff --git a/Source/cmConnection.h b/Source/cmConnection.h
index f9d50de..b1b51fe 100644
--- a/Source/cmConnection.h
+++ b/Source/cmConnection.h
@@ -100,7 +100,12 @@ public:
uv_stream_t* WriteStream = nullptr;
static void on_close(uv_handle_t* handle);
- static void on_close_delete(uv_handle_t* handle);
+
+ template <typename T>
+ static void on_close_delete(uv_handle_t* handle)
+ {
+ delete reinterpret_cast<T*>(handle);
+ }
protected:
std::string RawReadBuffer;
diff --git a/Source/cmPipeConnection.cxx b/Source/cmPipeConnection.cxx
index b18a1d6..9e565f6 100644
--- a/Source/cmPipeConnection.cxx
+++ b/Source/cmPipeConnection.cxx
@@ -19,7 +19,8 @@ void cmPipeConnection::Connect(uv_stream_t* server)
uv_pipe_init(this->Server->GetLoop(), rejectPipe, 0);
uv_accept(server, reinterpret_cast<uv_stream_t*>(rejectPipe));
- uv_close(reinterpret_cast<uv_handle_t*>(rejectPipe), &on_close_delete);
+ uv_close(reinterpret_cast<uv_handle_t*>(rejectPipe),
+ &on_close_delete<uv_pipe_t>);
return;
}
@@ -28,7 +29,8 @@ void cmPipeConnection::Connect(uv_stream_t* server)
this->ClientPipe->data = static_cast<cmEventBasedConnection*>(this);
auto client = reinterpret_cast<uv_stream_t*>(this->ClientPipe);
if (uv_accept(server, client) != 0) {
- uv_close(reinterpret_cast<uv_handle_t*>(client), &on_close_delete);
+ uv_close(reinterpret_cast<uv_handle_t*>(client),
+ &on_close_delete<uv_pipe_t>);
this->ClientPipe = nullptr;
return;
}
@@ -65,15 +67,16 @@ bool cmPipeConnection::OnConnectionShuttingDown()
{
if (this->ClientPipe) {
uv_close(reinterpret_cast<uv_handle_t*>(this->ClientPipe),
- &on_close_delete);
+ &on_close_delete<uv_pipe_t>);
this->WriteStream->data = nullptr;
}
- uv_close(reinterpret_cast<uv_handle_t*>(this->ServerPipe), &on_close_delete);
+ uv_close(reinterpret_cast<uv_handle_t*>(this->ServerPipe),
+ &on_close_delete<uv_pipe_t>);
this->ClientPipe = nullptr;
this->ServerPipe = nullptr;
this->WriteStream = nullptr;
this->ReadStream = nullptr;
- return cmConnection::OnConnectionShuttingDown();
+ return cmEventBasedConnection::OnConnectionShuttingDown();
}
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);
}
diff --git a/Source/cmServer.h b/Source/cmServer.h
index 9d8473d..93ac69e 100644
--- a/Source/cmServer.h
+++ b/Source/cmServer.h
@@ -66,6 +66,7 @@ protected:
bool ServeThreadRunning = false;
uv_thread_t ServeThread;
+ uv_async_t ShutdownSignal;
uv_loop_t Loop;
diff --git a/Source/cmServerConnection.cxx b/Source/cmServerConnection.cxx
index 4891131..d6bf1a8 100644
--- a/Source/cmServerConnection.cxx
+++ b/Source/cmServerConnection.cxx
@@ -62,14 +62,14 @@ bool cmStdIoConnection::OnConnectionShuttingDown()
if (usesTty) {
uv_read_stop(reinterpret_cast<uv_stream_t*>(this->Input.tty));
uv_close(reinterpret_cast<uv_handle_t*>(this->Input.tty),
- &on_close_delete);
+ &on_close_delete<uv_tty_t>);
uv_close(reinterpret_cast<uv_handle_t*>(this->Output.tty),
- &on_close_delete);
+ &on_close_delete<uv_tty_t>);
} else {
uv_close(reinterpret_cast<uv_handle_t*>(this->Input.pipe),
- &on_close_delete);
+ &on_close_delete<uv_pipe_t>);
uv_close(reinterpret_cast<uv_handle_t*>(this->Output.pipe),
- &on_close_delete);
+ &on_close_delete<uv_pipe_t>);
}
return true;