From 870579d38fdc81598c88268ee6a806b5b7b2ccfd Mon Sep 17 00:00:00 2001 From: Weiyi Wang Date: Mon, 4 Mar 2019 11:05:07 -0500 Subject: [PATCH] rpc: send ending packet in Server instead of UDPServer udp_server might not be created due to error (occupied port etc.), in which case its destructor and thread-ending call chain will not be excuted in Server::Stop. However, the ending packet still need to be send no matter udp is on or not, so move it to Server::Stop --- src/core/rpc/server.cpp | 1 + src/core/rpc/udp_server.cpp | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/core/rpc/server.cpp b/src/core/rpc/server.cpp index 3474fa7e1..358afa357 100644 --- a/src/core/rpc/server.cpp +++ b/src/core/rpc/server.cpp @@ -25,6 +25,7 @@ void Server::Start() { void Server::Stop() { udp_server.reset(); + NewRequestCallback(nullptr); // Notify the RPC server to end } void Server::NewRequestCallback(std::unique_ptr new_request) { diff --git a/src/core/rpc/udp_server.cpp b/src/core/rpc/udp_server.cpp index 185450f5e..a56097377 100644 --- a/src/core/rpc/udp_server.cpp +++ b/src/core/rpc/udp_server.cpp @@ -20,10 +20,7 @@ public: new_request_callback(std::move(new_request_callback)) { StartReceive(); - worker_thread = std::thread([this] { - io_context.run(); - this->new_request_callback(nullptr); - }); + worker_thread = std::thread([this] { io_context.run(); }); } ~Impl() {