From c7b9a3cd5db84739d622ca9150c68113b43b15f4 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Tue, 1 Oct 2024 09:43:20 +0700 Subject: [PATCH 1/2] fix: ignore sigint for server --- engine/main.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/engine/main.cc b/engine/main.cc index c461342c9..f10eebd2a 100644 --- a/engine/main.cc +++ b/engine/main.cc @@ -28,6 +28,7 @@ #endif void RunServer() { + signal(SIGINT, SIG_IGN); auto config = file_manager_utils::GetCortexConfig(); std::cout << "Host: " << config.apiServerHost << " Port: " << config.apiServerPort << "\n"; @@ -82,6 +83,7 @@ void RunServer() { std::stoi(config.apiServerPort)); drogon::app().setThreadNum(drogon_thread_num); LOG_INFO << "Number of thread is:" << drogon::app().getThreadNum(); + drogon::app().disableSigtermHandling(); drogon::app().run(); // return 0; From 27902604feef600adefde7fbd1442a034575b475 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Tue, 1 Oct 2024 10:18:18 +0700 Subject: [PATCH 2/2] fix: windows --- engine/main.cc | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/engine/main.cc b/engine/main.cc index f10eebd2a..e5cac996b 100644 --- a/engine/main.cc +++ b/engine/main.cc @@ -28,7 +28,15 @@ #endif void RunServer() { +#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) signal(SIGINT, SIG_IGN); +#elif defined(_WIN32) + auto console_ctrl_handler = +[](DWORD ctrl_type) -> BOOL { + return (ctrl_type == CTRL_C_EVENT) ? true : false; + }; + SetConsoleCtrlHandler( + reinterpret_cast(console_ctrl_handler), true); +#endif auto config = file_manager_utils::GetCortexConfig(); std::cout << "Host: " << config.apiServerHost << " Port: " << config.apiServerPort << "\n"; @@ -49,23 +57,8 @@ void RunServer() { [&]() { asyncFileLogger.flush(); }); LOG_INFO << "Host: " << config.apiServerHost << " Port: " << config.apiServerPort << "\n"; - // Number of cortex.cpp threads - // if (argc > 1) { - // thread_num = std::atoi(argv[1]); - // } - // // Check for host argument - // if (argc > 2) { - // host = argv[2]; - // } - - // // Check for port argument - // if (argc > 3) { - // port = std::atoi(argv[3]); // Convert string argument to int - // } int thread_num = 1; - // std::string host = "127.0.0.1"; - // int port = 3928; int logical_cores = std::thread::hardware_concurrency(); int drogon_thread_num = std::max(thread_num, logical_cores); @@ -163,4 +156,4 @@ int main(int argc, char* argv[]) { CommandLineParser clp; clp.SetupCommand(argc, argv); return 0; -} +} \ No newline at end of file