-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWebServer.hpp
61 lines (47 loc) · 1.13 KB
/
WebServer.hpp
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
#pragma once
/* C headers*/
#include <string.h>
#include <sys/epoll.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
/* C++ headers*/
#include <iostream>
#include <exception>
#include <vector>
#include <algorithm>
/* Classes */
#include <ConnStream.hpp>
#include <ServerError.hpp>
#include <ServerContext.hpp>
/* Utils */
#include <__webserv_utils.hpp>
static volatile sig_atomic_t is_running = 1;
using namespace ServerUtils;
class WebServer
{
private:
int max_events;
int epoll_fd;
std::map<int, ServerContext *> servers;
std::vector<t_event> events; // epoll_events
int failed;
// * Connections
std::map<int, ConnStream *> streams;
public:
WebServer(std::list<t_server> serverNodes);
~WebServer();
void listen(void);
void init_servers(std::vector<ServerContext *>&);
void accept_connection(int, int);
void read_request(int, int, t_event);
void send_response(int, int, t_event);
void close_conn(int, int);
void time_out(int);
static void sig_handler(int sig); // * Handles Ctrl + c
};