Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignore SIGINT for server #1371

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading