drogonframework / drogon

Drogon: A C++14/17/20 based HTTP web application framework running on Linux/macOS/Unix/Windows
MIT License
11.04k stars 1.06k forks source link

drogon hides the system sigint signal handler function? #2001

Closed bethebest0622 closed 2 months ago

bethebest0622 commented 2 months ago

I want to catch SIGINT signal in my main thread. I do this:

void signal_handler(int num) {
  EE("system interrupt here reached\n");
}

void sg() {
  EE("here reached\n");
}

int main(int argc, char** argv) {
  MAIN_CONFIG("cryptodata");

  std::thread t([] () {
    INFO("HttpClient Framework Start %d\n", drogon::app().isRunning());
    drogon::app().setIntSignalHandler(sg);
    drogon::app().run();
  });
  t.detach();
  signal(SIGINT, signal_handler);
  while (1);
}

then i type ctrl-c, i found the signal only be caught by drogon's signal function, main thread signal handler function not be called.

by the way, my program needs a non-block async request stream class, each class object need a EventLoopThreadPool. so i put the app().run() in a seperate thread.

could you help on this?

an-tao commented 2 months ago

Drogon handles SIGINT by default, you could set the handle_sig_term option to false in the configuration file or call the disableSigtermHandling method.