-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
68 lines (60 loc) · 2.19 KB
/
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mgo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/12 11:20:10 by mgo #+# #+# */
/* Updated: 2022/10/12 12:00:31 by mgo ### ########.fr */
/* */
/* ************************************************************************** */
#include "Server.hpp"
#include "Command.hpp"
#include "Protocol.hpp"
#include "Singleton.hpp"
#include <iostream>
static void singleton_equip_server(Server* ptr_sv)
{
Singleton& sngltn(Singleton::getInstance());
sngltn.setServerPtr(ptr_sv);
}
static void set_server_off(int sig)
{
Singleton& sngltn(Singleton::getInstance());
Server* sv;
Protocol* prtcl;
sv = sngltn.getServerPtr();
prtcl = sv->getProtocol();
sv->requestAllClientsToDisconnect();
if (sig == SIGINT)
sv->sendErrorClosingLinkProtoToAllClientsWithMsg("SIGINT in server");
else if (sig == SIGQUIT)
sv->sendErrorClosingLinkProtoToAllClientsWithMsg("SIGQUIT in server");
else if (sig == SIGTERM)
{
sv->sendErrorClosingLinkProtoToAllClientsWithMsg("SIGTERM in server");
std::cout << "hena god in SIGTERM\n";
}
sv->setStatusOff();
std::cout << "signum: [" << sig << "]\n";
}
static void set_signal_handler(void)
{
signal(SIGINT, set_server_off);
signal(SIGQUIT, set_server_off);
signal(SIGTERM, set_server_off);
signal(SIGPIPE, SIG_IGN);
}
int main(int argc, char *argv[])
{
Server irc_server(argc, argv);
Protocol proto(&irc_server);
Command cmd(&irc_server, &proto);
singleton_equip_server(&irc_server);
set_signal_handler();
irc_server.equipCommandAndProtocol(&cmd, &proto);
while (irc_server.getStatus())
irc_server.Run();
return (0);
}