You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.2 KiB

#include "webserv.hpp"
fd_set Socket::_readfds;
2 years ago
int Socket::_max_fd;
int Socket::_min_fd = INT_MAX;
int Socket::_amount = 0;
2 years ago
int main(int ac, char **av) {
if (ac <= 2) {
std::string config = "default.json";
if (ac == 2){
std::ifstream file(av[1]);
if (file.good())
config = av[1];
else {
std::cout << "Error: " << av[1] << " is not a valid file" << std::endl;
return EXIT_FAILURE;
}
config = av[1];
}
2 years ago
cout << "Parsing configuration file from JSON conf file.\n";
cout << "You must be sure the syntax is correct\n";
JSONParser parser(config);
2 years ago
JSONNode *conf = parser.parse();
2 years ago
cout << "Initialization of server...\n";
2 years ago
Env env(conf);
2 years ago
while (1) {
FD_ZERO(&Socket::_readfds);
2 years ago
Socket::_max_fd = Socket::_min_fd;
2 years ago
cout << "==> Check sockets still alive to listen\n";
2 years ago
env.set_fds();
2 years ago
cout << "|===||===| Waiting some HTTP request... |===||===|\n";
2 years ago
int activity = select(Socket::_max_fd + Socket::_amount,
&(Socket::_readfds), NULL, NULL, NULL);
if ((activity < 0) && (errno != EINTR))
cout << "Select: " << strerror(errno) << "\n";
2 years ago
cout << "==> Handle requests and answers:\n";
2 years ago
env.refresh();
}
}
else
cout << "Usage:\n./webserv CONF.json\n";
2 years ago
return (0);
2 years ago
}