Skip to content

Commit 5c2cae1

Browse files
fix: ignore SIGINT for server (#1371)
* fix: ignore sigint for server * fix: windows --------- Co-authored-by: vansangpfiev <[email protected]>
1 parent db6d822 commit 5c2cae1

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

engine/main.cc

+11-16
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@
2828
#endif
2929

3030
void RunServer() {
31+
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
32+
signal(SIGINT, SIG_IGN);
33+
#elif defined(_WIN32)
34+
auto console_ctrl_handler = +[](DWORD ctrl_type) -> BOOL {
35+
return (ctrl_type == CTRL_C_EVENT) ? true : false;
36+
};
37+
SetConsoleCtrlHandler(
38+
reinterpret_cast<PHANDLER_ROUTINE>(console_ctrl_handler), true);
39+
#endif
3140
auto config = file_manager_utils::GetCortexConfig();
3241
std::cout << "Host: " << config.apiServerHost
3342
<< " Port: " << config.apiServerPort << "\n";
@@ -48,23 +57,8 @@ void RunServer() {
4857
[&]() { asyncFileLogger.flush(); });
4958
LOG_INFO << "Host: " << config.apiServerHost
5059
<< " Port: " << config.apiServerPort << "\n";
51-
// Number of cortex.cpp threads
52-
// if (argc > 1) {
53-
// thread_num = std::atoi(argv[1]);
54-
// }
5560

56-
// // Check for host argument
57-
// if (argc > 2) {
58-
// host = argv[2];
59-
// }
60-
61-
// // Check for port argument
62-
// if (argc > 3) {
63-
// port = std::atoi(argv[3]); // Convert string argument to int
64-
// }
6561
int thread_num = 1;
66-
// std::string host = "127.0.0.1";
67-
// int port = 3928;
6862

6963
int logical_cores = std::thread::hardware_concurrency();
7064
int drogon_thread_num = std::max(thread_num, logical_cores);
@@ -82,6 +76,7 @@ void RunServer() {
8276
std::stoi(config.apiServerPort));
8377
drogon::app().setThreadNum(drogon_thread_num);
8478
LOG_INFO << "Number of thread is:" << drogon::app().getThreadNum();
79+
drogon::app().disableSigtermHandling();
8580

8681
drogon::app().run();
8782
// return 0;
@@ -161,4 +156,4 @@ int main(int argc, char* argv[]) {
161156
CommandLineParser clp;
162157
clp.SetupCommand(argc, argv);
163158
return 0;
164-
}
159+
}

0 commit comments

Comments
 (0)