diff options
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp index 8b800dd..463d44d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,31 @@ #include "chatServer.hpp" +#include <csignal> +#include "log.hpp" + +static void handleSignal(int sig) { + signal(sig, SIG_DFL); + + log(SYS, "Caught signal: {}", sig); + + switch (sig) { + default: + std::exit(0); + break; + } +} + +static void registerSignals() { + signal(SIGINT, handleSignal); + signal(SIGTERM, handleSignal); + + // client may not finish reading hence the server will receive SIGPIPE, we don't want that to just crash the server + signal(SIGPIPE, SIG_IGN); +} // TODO: ARGC, ARGV. the CServer ctor should take a port number int main() { + registerSignals(); + g_pChatServer = std::make_unique<CChatServer>(); g_pChatServer->start(); |
