From 131dc244e67e3b6e9304e7076c397c761860044c Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Mon, 10 Mar 2025 18:36:00 +0800 Subject: fix(registerName): no longer allow same name the previous behaviour was it wouldn't broadcast the message to the same name debug: more logging, maybe we should disable TRACE by default in the future? WIP: partial impl of signal handling(SIGINT(keyboardinterrupt) etc) --- src/main.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/main.cpp') 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 +#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(); g_pChatServer->start(); -- cgit v1.2.3