Client struct, signal wip, refactoring
This commit is contained in:
@@ -2,14 +2,15 @@
|
||||
#ifndef WEBSERV_HPP
|
||||
# define WEBSERV_HPP
|
||||
|
||||
# include <iostream> // cout, cin
|
||||
# include <string>
|
||||
# include <map>
|
||||
# include <vector>
|
||||
# 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
|
||||
@@ -20,11 +21,33 @@
|
||||
# include <sys/epoll.h> // epoll
|
||||
# include <fcntl.h> // fcntl
|
||||
|
||||
#define BUFSIZE 8192
|
||||
#define TIMEOUT 3000
|
||||
#define MAX_EVENTS 42 // arbitrary
|
||||
#define MSG_TEST "Le Webserv / 20 =D\n"
|
||||
#define MSG_BOUNCE "bounced properly ;)\n" // placeholder
|
||||
# include "Client.hpp"
|
||||
# include "Server.hpp"
|
||||
# include <csignal> // signal
|
||||
|
||||
# define BUFSIZE 8192
|
||||
# define TIMEOUT 3000
|
||||
# define MAX_EVENTS 42 // arbitrary
|
||||
# define MSG_TEST "Le Webserv / 20 =D\n"
|
||||
|
||||
|
||||
// ev.data.u32 filled with tag constant "SERVER_FD/CLIENT_FD"
|
||||
// dont work because ev.data is an "union",
|
||||
// so we can only use one variable (fd, ptr, u32 or u64)
|
||||
// ev.data.u32 = SERVER_FD;
|
||||
|
||||
/* enum // WIP test
|
||||
{
|
||||
SERVER_FD = 1,
|
||||
CLIENT_FD
|
||||
};
|
||||
|
||||
struct s // WIP test
|
||||
{
|
||||
int fd;
|
||||
Client *ptr;
|
||||
};
|
||||
*/
|
||||
|
||||
class Webserv
|
||||
{
|
||||
@@ -38,20 +61,26 @@ class Webserv
|
||||
void start();
|
||||
|
||||
private:
|
||||
int _socket_fd; // TODO: replace with vector of "Server" struct
|
||||
int _epfd;
|
||||
int _socket_fd; // temp, to replace with std::vector<Server>
|
||||
// std::vector<Server> _servers;
|
||||
std::vector<Client> _clients;
|
||||
|
||||
// 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 _accept_connection(int fd);
|
||||
void _read_request(Client *client);
|
||||
void _send_response(Client *client);
|
||||
|
||||
int _epoll_update(int fd, uint32_t events, int op);
|
||||
int _epoll_update(int fd, uint32_t events, int op, void *ptr);
|
||||
|
||||
void _handle_last_signal();
|
||||
// void _signal_handler(int signum); // invalide dans une class
|
||||
Client* _actual_client;
|
||||
void _close_client(int fd);
|
||||
void _close_all_clients();
|
||||
|
||||
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