forked from tgrasset/webserv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
62 lines (58 loc) · 1.75 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbocquel <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/09 20:36:38 by mbocquel #+# #+# */
/* Updated: 2023/09/08 16:46:28 by mbocquel ### ########.fr */
/* */
/* ************************************************************************** */
#include "webserv.hpp"
#include "ConfParser.hpp"
#include "Server.hpp"
#include "Launcher.hpp"
void handle_sigint(int sig)
{
throw Launcher::SigException();
(void)sig;
}
void handle_sigpipe(int sig)
{
(void)sig;
}
int main(int ac, char **av)
{
if (ac > 2)
{
std::cerr << "Error: Too many arguments" << std::endl;
return (1);
}
std::string path;
if (ac == 1)
path = "./configs/default.conf";
else
path = av[1];
Launcher launcher(path);
try {
signal(SIGINT, &handle_sigint);
signal(SIGPIPE, &handle_sigpipe);
launcher.testFolderTmp();
launcher.parse();
launcher.launchServers();
}
catch (Launcher::SigException &e) {
std::cerr << std::endl << "See you soon!" << std::endl;
return (EXIT_SUCCESS);
}
catch (CGI::CGIexception &e)
{
return (EXIT_SUCCESS);
}
catch (std::exception &e) {
std::cerr << e.what() << std::endl;
return (EXIT_FAILURE);
}
return (0);
}