forked from lxu-wu/42_webserv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
54 lines (46 loc) · 1.1 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
#include "server/server.hpp"
Server serv;
void deleteallfd(Server serv)
{
for(size_t i = 0; i < serv.getSocketList().size(); i++)
{
close(serv.getSocketList()[i].getServerSocket());
}
for(size_t i = 0; i < serv.getClientsList().size(); i++)
{
close(serv.getClientsList()[i].getClientSocket());
}
std::cout << colors::green << "Clean All Fd" << std::endl;
}
void sig_handler(int signal)
{
(void)signal;
for(size_t i = 0; i < serv.getSocketList().size(); i++)
close(serv.getSocketList()[i].getServerSocket());
for(size_t i = 0; i < serv.getClientsList().size(); i++)
close(serv.getClientsList()[i].getClientSocket());
exit(0);
}
int main(int ac, char **av, char **envp)
{
Conf data;
try
{
parsing(ac, av, data);
}
catch(const std::exception& e)
{
std::cerr << e.what() << std::endl;
return (1);
}
serv.servers = data.getServers();
serv.envp = envp;
serv.initServer();
signal(SIGINT, sig_handler);
while(1)
{
serv.waitClient();
serv.acceptClient();
serv.handleRequest();
}
}