summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-03-10 18:36:00 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-03-20 23:44:58 +0800
commit131dc244e67e3b6e9304e7076c397c761860044c (patch)
tree56f634c1a16c4e5b6eb2224ba876ca97f68e4dee /src/main.cpp
parent4e8644b8ab3b259a91387c93a3295092bd9757a0 (diff)
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)
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp24
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();