summaryrefslogtreecommitdiff
path: root/src/main.cpp
blob: 463d44dc1a815f7417c86478e1c085d2a43136c6 (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
#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();

  // died
  g_pChatServer->cleanup();
  g_pChatServer.reset();

  return 0;
}