-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.cpp
47 lines (39 loc) · 978 Bytes
/
main.cpp
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
43
44
45
46
47
#include "Messenger.h"
#include "Client.h"
#include "FileConstants.h"
#include <iostream>
#include <fstream>
using namespace std;
Messenger* m = 0;
Client* l = 0;
int gEnd = 0;
void CtrlC(int aSig) {
if (gEnd==0) {
cout << endl << "[C-c] Trying a clean exit!" << endl;
if (m) { cout << "Trying to disconnect the messenger" << endl; delete m; }
if (l) { cout << "Trying to disconnect the first client" << endl; delete l; }
exit(0);
}
else if (gEnd>=5) {
cout << endl << "[C-c > 5 times] ... Forcing exit!" << endl;
exit(0);
}
gEnd++;
}
int main(int argc, char* argv[])
{
signal(SIGINT, CtrlC);
// Where to put the logs
ofstream err_log("master.err", ios::binary);
const Logger lr(err_log, cerr);
m = new Messenger(1987);
if (!m->Connect()) {
cout << "Failed to connect the messenger!" << endl;
return -1;
}
while (true) {
try { m->Receive(); } catch (Exception& e) { e.Dump(); }
}
delete m;
return 0;
}