-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
44 lines (41 loc) · 2 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mpedroso <mpedroso@student.42lisboa.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 13:46:03 by anlima #+# #+# */
/* Updated: 2024/08/26 15:49:12 by mpedroso ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes/Directive.hpp"
#include "includes/Location.hpp"
#include "includes/Parser.hpp"
#include "includes/Processes.hpp"
#include "includes/Requests.hpp"
#include "includes/Server.hpp"
#include "includes/Sockets.hpp"
#include "includes/macros.hpp"
int main(int argc, char **argv) {
if (argc != 2) {
Processes::handleError("Error! Usage => ./webserv <config filename>");
return (1);
}
try {
std::vector<struct pollfd> fds;
std::vector<Server> servers = Parser::parseConf(argv[1]);
for (size_t i = 0; i < servers.size(); ++i) {
servers[i].setSocket(Sockets::createServer(servers[i].getServerName(), servers[i].getPort()));
for (size_t j = 0; j < servers[i].getSocket().size(); ++j) {
servers[i].setPollfd(Sockets::createPollfd(servers[i].getSocket()[j]));
Sockets::setNonBlocking(servers[i].getPollfd()[j].fd);
fds.push_back(servers[i].getPollfd()[j]);
}
}
Requests::handleConn(fds, servers);
} catch (const std::exception &e) {
std::cout << e.what() << '\n';
}
return (0);
}