forked from YbencheL/WEBSERV
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
63 lines (57 loc) · 1.62 KB
/
main.cpp
File metadata and controls
63 lines (57 loc) · 1.62 KB
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
# include "./socket_engine.hpp"
# include "./config_parsing/includes/ConfigPars.hpp"
# include "./cookies_sessions/includes/SessionManager.hpp"
# include "./utils/utils.hpp"
# include <csignal>
#include <sys/time.h>
socket_engine s_engine;
void signal_handler(int sig_flag) {
(void)sig_flag;
const char msg[] = "\033[3;43;30m\n[!] SIGINT received, shutting down gracefully...\033[0m";
throw std::runtime_error(msg);
}
int main(int ac, char **av)
{
std::signal(SIGPIPE, SIG_IGN);
std::signal(SIGINT, signal_handler);
std::deque<ServerBlock> ServerConfig;
std::string fileName;
timeval t1;
gettimeofday(&t1, NULL);
std::srand(t1.tv_sec * 1000 + t1.tv_usec / 1000);
if (ac < 2)
fileName = "./config.conf";
else
fileName = av[1];
std::ifstream infile(fileName.c_str());
std::string fileContent((std::istreambuf_iterator<char>(infile)), std::istreambuf_iterator<char>());
if (infile.fail())
{
std::cout << "Error: can't open file!" << std::endl;
s_engine.free_fds_list();
return 1;
}
try
{
ServerConfig = tokenzation(fileContent);
}
catch(const std::exception& e)
{
std::cerr << e.what() << '\n';
s_engine.free_fds_list();
return 1;
}
try
{
signal(SIGINT, signal_handler);
s_engine.set_server_config_info(ServerConfig);
setup_server_config_info(ServerConfig); // >> logs
s_engine.process_connections();
}
catch(const std::exception& e)
{
std::cerr << e.what() << '\n';
s_engine.free_fds_list();
}
return (0);
}