blob: 3288b5c8de655e50e0945eb160047c0642dfd26a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#include "chatServer.hpp"
#include <csignal>
#include "log.hpp"
#include <unistd.h>
static void handleSignal(int sig) {
signal(sig, SIG_DFL);
log(SYS, "Caught signal: {}", sig);
switch (sig) {
default:
// quick_exit(less cleanup) if the cleanup took too long
signal(SIGALRM, [](int) { std::quick_exit(1); });
alarm(5);
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();
// died
g_pChatServer->cleanup();
g_pChatServer.reset();
return 0;
}
|