-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
54 lines (46 loc) · 1.44 KB
/
Copy pathmain.cpp
File metadata and controls
54 lines (46 loc) · 1.44 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
#include "ServerEngine.hpp"
#include "Config.hpp"
#include "ConfigParser.hpp"
#include "Debug.hpp"
#include "Location.hpp"
#include <iostream>
#include <string>
ServerEngine *engine = NULL;
// Path for the default config file
#define DEFAULT_CONFIGFILE "./config/default.conf"
void signalHandler(int sig) {
std::cout << std::endl << "Interrupted by Ctrl + C : SIGINT: signo: " << sig << std::endl;
delete engine;
exit(100);
}
/*
If no argumens or one empty argument
-> load the default configuration file
If one argument that is not empty
-> load the config file/path denoted by argv[1]
If more than one argument
-> print the usage message
*/
int main(int argc, char** argv) {
signal(SIGPIPE, SIG_IGN); // avoid SIGPIPE crashes
signal(SIGINT, signalHandler); // SIGINT handler for clean exit
// ServerEngine engine;
engine = new ServerEngine();
if (argc == 1 || (argc == 2 && argv[1][0] == '\0')) {
engine->name = std::string(DEFAULT_CONFIGFILE);
if (engine->start(engine->name) == -1) {
delete engine;
return 1;
}
} else if (argc == 2 && argv[1][0] != '\0') {
engine->name = std::string(argv[1]);
if (engine->start(engine->name) == -1) {
delete engine;
return 1;
}
} else {
delete engine;
std::cout << "Usage: ./webserv [config_file]" << std::endl;
}
return 0;
}