forked from itseugen/Webserv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
63 lines (58 loc) · 1.84 KB
/
main.cpp
File metadata and controls
63 lines (58 loc) · 1.84 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
55
56
57
58
59
60
61
62
63
#include "webserv.h"
#include "server/SocketManager.hpp"
/*
* Use curl localhost:PORT (replace port with actual value) to test responses
* USE wrk -t12 -c400 -d30s http://localhost:8080 to stress test server
* -t12 stands for 12 threads
* -c400 stands for 400 connections
* -d30s stands for a 30s test lenght
*/
void signalHandler(int signum)
{
std::cout << "Interrupt signal (" << signum << ") received.\n";
throw InterruptSignal();
}
int main(int argc, char **argv)
{
if (argc > 2)
{
std::cout << ERROR("use either ") << UNDERLINE("./webserv") << " or "
<< UNDERLINE("./webserv <path_to_config_file>") << std::endl;
return 0;
}
std::cout << GREEN("\n🚀 Webserv is up and running ... 🚀\n") << std::endl;
std::cout << YELLOW(BOLD("💡 TIP: ")) << "For server's " << BOLD("output")
<< " check the " << UNDERLINE("Log directory") << ". 📁 🔍" << std::endl;
std::vector<ServerData> server_vec;
try
{
if (argc == 2)
server_vec = read_config_file(argv[1]);
else
server_vec = read_config_file("config_files/default.conf");
}
catch(const std::exception& e)
{
std::cerr << RED("❗ " << UNDERLINE(e.what())) << std::endl;
return (0);
}
std::signal(SIGINT, signalHandler);
try
{
size_t global_timeout = server_vec[0].global_timeout;
SocketManager socket_manager(global_timeout);
MimeTypes::getInstance();
for (size_t s = 0; s < server_vec.size(); s++)
{
ServerData const & server = server_vec[s];
socket_manager.add_server(server.port_to_listen, std::make_unique<Server>(server.server_name, server.port_to_listen, server.index_file,
"usrimg", server.root, server.directory_listing, server.keepalive_timeout, server.send_timeout, server.max_request_size, server.locations));
}
socket_manager.handle_requests();
}
catch (const std::exception& e)
{
Logger::getInstance().log("", e.what(), 4);
}
return (0);
}