|
|
@ -6,23 +6,26 @@ int Master::_min_fd = INT_MAX; |
|
|
|
int Master::_amount = 0; |
|
|
|
|
|
|
|
int main(int ac, char **av) { |
|
|
|
if (ac != 2) { |
|
|
|
cout << "Usage:\n./webserv CONF.json\n"; |
|
|
|
return EXIT_SUCCESS; |
|
|
|
try { |
|
|
|
if (ac > 2) |
|
|
|
throw std::runtime_error("Too many arguments"); |
|
|
|
std::string config_file = "default.json"; |
|
|
|
if (ac == 2) |
|
|
|
config_file = av[1]; |
|
|
|
std::ifstream file(config_file); |
|
|
|
if (!file.good()) |
|
|
|
throw std::runtime_error("File not found"); |
|
|
|
cout << "Parsing configuration file from JSON conf file.\n"; |
|
|
|
cout << "You must be sure the syntax is correct\n"; |
|
|
|
JSONParser parser(config_file); |
|
|
|
JSONNode *conf = parser.parse(); |
|
|
|
cout << "Initialization of server...\n"; |
|
|
|
Env env(conf); |
|
|
|
while (1) |
|
|
|
env.cycle(); |
|
|
|
} |
|
|
|
|
|
|
|
std::ifstream file(av[1]); |
|
|
|
if (!file.good()) { |
|
|
|
cout << "Error: " << av[1] << " is not a valid file\n"; |
|
|
|
return EXIT_FAILURE; |
|
|
|
catch(const std::exception& e) { |
|
|
|
std::cerr << e.what() << '\n'; |
|
|
|
} |
|
|
|
cout << "Parsing configuration file from JSON conf file.\n"; |
|
|
|
cout << "You must be sure the syntax is correct\n"; |
|
|
|
JSONParser parser(av[1]); |
|
|
|
JSONNode *conf = parser.parse(); |
|
|
|
cout << "Initialization of server...\n"; |
|
|
|
Env env(conf); |
|
|
|
while (1) |
|
|
|
env.cycle(); |
|
|
|
return EXIT_SUCCESS; |
|
|
|
} |
|
|
|