add luke epoll version
This commit is contained in:
57
headers/Webserv.hpp
Normal file
57
headers/Webserv.hpp
Normal file
@@ -0,0 +1,57 @@
|
||||
|
||||
#ifndef WEBSERV_HPP
|
||||
# define WEBSERV_HPP
|
||||
|
||||
# include <string>
|
||||
# include <map>
|
||||
# include <cerrno> // errno
|
||||
# include <cstdio> // perror
|
||||
# include <exception>
|
||||
# include <stdexcept>
|
||||
# include <unistd.h> // close
|
||||
# include <iostream> // cout, cin
|
||||
# include <cstring> // memset
|
||||
|
||||
# include <sys/socket.h> // socket, accept, listen, send, recv, bind, connect, setsockopt, getsockname
|
||||
# include <netinet/in.h> // sockaddr_in
|
||||
// # include <netinet/ip.h> // usefull for what ?
|
||||
# include <arpa/inet.h> // htonl, htons, ntohl, ntohs, inet_addr
|
||||
|
||||
# include <sys/epoll.h> // epoll
|
||||
# include <fcntl.h> // fcntl
|
||||
|
||||
#define BUFSIZE 8192
|
||||
#define TIMEOUT 3 * 60 * 1000
|
||||
#define MAX_EVENTS 42 // arbitrary
|
||||
#define MSG_TEST "Le Webserv / 20 =D\n"
|
||||
#define MSG_BOUNCE "bounced properly ;)\n" // placeholder
|
||||
|
||||
class Webserv
|
||||
{
|
||||
public:
|
||||
Webserv();
|
||||
// Webserv(Webserv const &src);
|
||||
~Webserv();
|
||||
// Webserv &operator=(Webserv const &rhs);
|
||||
|
||||
void init_virtual_servers(); // ADD config param
|
||||
void start();
|
||||
|
||||
private:
|
||||
int _socket_fd; // TODO: replace with vector of "Server" struct
|
||||
int _epfd;
|
||||
|
||||
// WIP global buffer. Need one variable set per "Client"
|
||||
char _buf[BUFSIZE+1];
|
||||
ssize_t _read_ret;
|
||||
std::map<std::string, std::string> _request;
|
||||
std::map<std::string, std::string> _response;
|
||||
|
||||
void _bind(int socket_fd, in_port_t port);
|
||||
void _listen(int socket_fd, unsigned int max_connections);
|
||||
void _accept_connection(int fd);
|
||||
void _read_request(int fd);
|
||||
void _send_response(int fd);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user