Skip to content

Commit

Permalink
fix: ignore SIGINT for server (#1371)
Browse files Browse the repository at this point in the history
* fix: ignore sigint for server

* fix: windows

---------

Co-authored-by: vansangpfiev <[email protected]>
  • Loading branch information
vansangpfiev and sangjanai authored Oct 1, 2024
1 parent db6d822 commit 5c2cae1
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions engine/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +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<PHANDLER_ROUTINE>(console_ctrl_handler), true);
#endif
auto config = file_manager_utils::GetCortexConfig();
std::cout << "Host: " << config.apiServerHost
<< " Port: " << config.apiServerPort << "\n";
Expand All @@ -48,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);
Expand All @@ -82,6 +76,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;
Expand Down Expand Up @@ -161,4 +156,4 @@ int main(int argc, char* argv[]) {
CommandLineParser clp;
clp.SetupCommand(argc, argv);
return 0;
}
}

0 comments on commit 5c2cae1

Please sign in to comment.