|
@ -6,16 +6,21 @@ int Socket::_min_fd = INT_MAX; |
|
|
int Socket::_amount = 0; |
|
|
int Socket::_amount = 0; |
|
|
|
|
|
|
|
|
int main(int ac, char **av) { |
|
|
int main(int ac, char **av) { |
|
|
|
|
|
if (ac <= 2) { |
|
|
if (ac < 2) { |
|
|
std::string config = "default.json"; |
|
|
cout << "Usage:\n"; |
|
|
if (ac == 2){ |
|
|
cout << "./webserv CONF.json\n"; |
|
|
std::ifstream file(av[1]); |
|
|
cout << "WARNING: You must use a correct json syntax and a correct " |
|
|
if (file.good()) |
|
|
"server configuration or don't expect it to work correctly."; |
|
|
config = av[1]; |
|
|
} else if (ac == 2) { |
|
|
else { |
|
|
|
|
|
std::cout << "Error: " << av[1] << " is not a valid file" << std::endl; |
|
|
|
|
|
return EXIT_FAILURE; |
|
|
|
|
|
} |
|
|
|
|
|
config = av[1]; |
|
|
|
|
|
} |
|
|
cout << "Parsing configuration file from JSON conf file.\n"; |
|
|
cout << "Parsing configuration file from JSON conf file.\n"; |
|
|
cout << "You must be sure the syntax is correct\n"; |
|
|
cout << "You must be sure the syntax is correct\n"; |
|
|
JSONParser parser(av[1]); |
|
|
JSONParser parser(config); |
|
|
JSONNode *conf = parser.parse(); |
|
|
JSONNode *conf = parser.parse(); |
|
|
cout << "Initialization of server...\n"; |
|
|
cout << "Initialization of server...\n"; |
|
|
Env env(conf); |
|
|
Env env(conf); |
|
@ -27,12 +32,14 @@ int main(int ac, char **av) { |
|
|
env.set_fds(); |
|
|
env.set_fds(); |
|
|
cout << "|===||===| Waiting some HTTP request... |===||===|\n"; |
|
|
cout << "|===||===| Waiting some HTTP request... |===||===|\n"; |
|
|
int activity = select(Socket::_max_fd + Socket::_amount, |
|
|
int activity = select(Socket::_max_fd + Socket::_amount, |
|
|
&(Socket::_readfds), NULL, NULL, NULL); |
|
|
&(Socket::_readfds), NULL, NULL, NULL); |
|
|
if ((activity < 0) && (errno != EINTR)) |
|
|
if ((activity < 0) && (errno != EINTR)) |
|
|
cout << "Select: " << strerror(errno) << "\n"; |
|
|
cout << "Select: " << strerror(errno) << "\n"; |
|
|
cout << "==> Handle requests and answers:\n"; |
|
|
cout << "==> Handle requests and answers:\n"; |
|
|
env.refresh(); |
|
|
env.refresh(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
cout << "Usage:\n./webserv CONF.json\n"; |
|
|
return (0); |
|
|
return (0); |
|
|
} |
|
|
} |
|
|