diff --git a/1.patch b/1.patch new file mode 100644 index 0000000000000000000000000000000000000000..bca1cd3138e216fd027631fc223b99b6d29243ba --- /dev/null +++ b/1.patch @@ -0,0 +1,91 @@ +diff --git a/src/observer/CMakeLists.txt b/src/observer/CMakeLists.txt +index 1e156f2..37f5f86 100644 +--- a/src/observer/CMakeLists.txt ++++ b/src/observer/CMakeLists.txt +@@ -24,7 +24,7 @@ FOREACH (F ${ALL_SRC}) + + ENDFOREACH (F) + +-SET(LIBRARIES common pthread dl event jsoncpp) ++SET(LIBRARIES common pthread dl event_pthreads event jsoncpp) + + # 指定目标文件位置 + SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/../../bin) +diff --git a/src/observer/main.cpp b/src/observer/main.cpp +index 4fff6da..112255e 100644 +--- a/src/observer/main.cpp ++++ b/src/observer/main.cpp +@@ -137,8 +137,6 @@ void *quit_thread_func(void *_signum) + LOG_INFO("Receive signal: %ld", signum); + if (g_server) { + g_server->shutdown(); +- delete g_server; +- g_server = nullptr; + } + return nullptr; + } +@@ -169,4 +167,6 @@ int main(int argc, char **argv) + LOG_INFO("Server stopped"); + + cleanup(); ++ ++ delete g_server; + } +diff --git a/src/observer/net/server.cpp b/src/observer/net/server.cpp +index e87ad0d..2c6cef6 100644 +--- a/src/observer/net/server.cpp ++++ b/src/observer/net/server.cpp +@@ -26,6 +26,7 @@ See the Mulan PSL v2 for more details. */ + #include + #include + #include ++#include + + #include "common/lang/mutex.h" + #include "common/log/log.h" +@@ -411,6 +412,7 @@ int Server::start_unix_socket_server() + + int Server::serve() + { ++ evthread_use_pthreads(); + event_base_ = event_base_new(); + if (event_base_ == nullptr) { + LOG_ERROR("Failed to create event base, %s.", strerror(errno)); +@@ -425,19 +427,6 @@ int Server::serve() + + event_base_dispatch(event_base_); + +- return 0; +-} +- +-void Server::shutdown() +-{ +- LOG_INFO("Server shutting down"); +- +- // cleanup +- struct timeval exit_time; +- gettimeofday(&exit_time, nullptr); +- exit_time.tv_sec += 10; +- event_base_loopexit(event_base_, &exit_time); +- + if (listen_ev_ != nullptr) { + event_del(listen_ev_); + event_free(listen_ev_); +@@ -451,4 +440,16 @@ void Server::shutdown() + + started_ = false; + LOG_INFO("Server quit"); ++ return 0; ++} ++ ++void Server::shutdown() ++{ ++ LOG_INFO("Server shutting down"); ++ ++ // cleanup ++ if (event_base_ != nullptr && started_) { ++ started_ = false; ++ event_base_loopexit(event_base_, nullptr); ++ } + } + diff --git a/src/observer/CMakeLists.txt b/src/observer/CMakeLists.txt index 1e156f28855ada245e08aaae8be92e8a92ae65fb..37f5f863b8798d698f46c824979ee2898b400ea0 100644 --- a/src/observer/CMakeLists.txt +++ b/src/observer/CMakeLists.txt @@ -24,7 +24,7 @@ FOREACH (F ${ALL_SRC}) ENDFOREACH (F) -SET(LIBRARIES common pthread dl event jsoncpp) +SET(LIBRARIES common pthread dl event_pthreads event jsoncpp) # 指定目标文件位置 SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/../../bin) diff --git a/src/observer/main.cpp b/src/observer/main.cpp index 4fff6dabafcb2e033e0149b145f6b2de212730c0..112255ebf4280f2a69c5ad30d1ece9a8a23c21ef 100644 --- a/src/observer/main.cpp +++ b/src/observer/main.cpp @@ -137,8 +137,6 @@ void *quit_thread_func(void *_signum) LOG_INFO("Receive signal: %ld", signum); if (g_server) { g_server->shutdown(); - delete g_server; - g_server = nullptr; } return nullptr; } @@ -169,4 +167,6 @@ int main(int argc, char **argv) LOG_INFO("Server stopped"); cleanup(); + + delete g_server; } diff --git a/src/observer/net/server.cpp b/src/observer/net/server.cpp index e87ad0df02f8af3daad8f90945cbc427d33547a6..2c6cef6dd9bb452b43e5d0125f30851a8fcd9307 100644 --- a/src/observer/net/server.cpp +++ b/src/observer/net/server.cpp @@ -26,6 +26,7 @@ See the Mulan PSL v2 for more details. */ #include #include #include +#include #include "common/lang/mutex.h" #include "common/log/log.h" @@ -411,6 +412,7 @@ int Server::start_unix_socket_server() int Server::serve() { + evthread_use_pthreads(); event_base_ = event_base_new(); if (event_base_ == nullptr) { LOG_ERROR("Failed to create event base, %s.", strerror(errno)); @@ -425,19 +427,6 @@ int Server::serve() event_base_dispatch(event_base_); - return 0; -} - -void Server::shutdown() -{ - LOG_INFO("Server shutting down"); - - // cleanup - struct timeval exit_time; - gettimeofday(&exit_time, nullptr); - exit_time.tv_sec += 10; - event_base_loopexit(event_base_, &exit_time); - if (listen_ev_ != nullptr) { event_del(listen_ev_); event_free(listen_ev_); @@ -451,4 +440,16 @@ void Server::shutdown() started_ = false; LOG_INFO("Server quit"); + return 0; +} + +void Server::shutdown() +{ + LOG_INFO("Server shutting down"); + + // cleanup + if (event_base_ != nullptr && started_) { + started_ = false; + event_base_loopexit(event_base_, nullptr); + } }