clean comment and stuff

This commit is contained in:
lperrey
2022-08-18 12:44:09 +02:00
parent 9b0fcc1520
commit 469eca8aa9
27 changed files with 100 additions and 325 deletions

View File

@@ -38,10 +38,6 @@ extern bool g_run;
extern int g_last_signal;
void signal_handler(int signum);
// these might only be TMP
# define FAILURE -1
# define SUCCESS 1
# define MIME_TYPE_DEFAULT "application/octet-stream"
class Webserv
@@ -49,13 +45,7 @@ class Webserv
public:
// base.cpp
Webserv();
// Webserv(Webserv const &src);
// what should it take as arg, *, &, ?
// Webserv(std::vector<ServerConfig>& servers);
~Webserv();
// Webserv &operator=(Webserv const &rhs);
// init.cpp
void init_virtual_servers(std::vector<ServerConfig>* servers);

View File

@@ -18,7 +18,12 @@ void Webserv::_accept_connection(listen_socket &lsocket)
_handle_last_signal();
return ;
}
::fcntl(accepted_fd, F_SETFL, O_NONBLOCK);
if (::fcntl(accepted_fd, F_SETFL, O_NONBLOCK) == -1)
{
std::perror("err fcntl()");
if (::close(accepted_fd) == -1)
std::perror("err close()");
}
infos = _extract_infos(addr);
Client new_client(accepted_fd, &lsocket, infos["port"], infos["ip"]);

View File

@@ -19,30 +19,6 @@ Webserv::Webserv()
std::signal(SIGINT, signal_handler);
}
/* Webserv::Webserv(Webserv const &src)
{
} */
// we'll come back to this
/*
Webserv::Webserv(std::vector<ServerConfig>* servers)
: _servers(servers)
{
// talk to luke about what all this does
// the Param Constructor might need to do dif stuff
std::cout << "Server init\n";
_epfd = ::epoll_create1(0); // (EPOLL_CLOEXEC) for CGI fork ?
if (_epfd == -1)
{
std::perror("err epoll_create1(): ");
throw std::runtime_error("Epoll init");
}
}
*/
Webserv::~Webserv()
{
close(_epfd);
@@ -50,8 +26,3 @@ Webserv::~Webserv()
_close_all_listen_sockets();
std::cerr << "Server destroyed\n";
}
/* Webserv & Webserv::operator=(Webserv const &rhs)
{
} */

View File

@@ -101,7 +101,6 @@ void Webserv::_cgi_open_pipes(Client *client)
void Webserv::_write_body_to_cgi(Client *client)
{
std::cerr << "_write_body_to_cgi()"; // DEBUG
ssize_t ret;
std::string body = client->get_rq_body();
@@ -157,25 +156,24 @@ std::string Webserv::_dup_env(std::string var, int i)
return (str);
}
// TODO : verifier que les variables sont corrects
/*
https://www.rfc-editor.org/rfc/rfc3875#section-4.1
*/
void Webserv::_set_env_vector(Client *client, std::vector<std::string> &env_vector)
{
env_vector.push_back(_dup_env("AUTH_TYPE")); // authentification not supporte
env_vector.push_back(_dup_env("AUTH_TYPE")); // authentification not supported
env_vector.push_back(_dup_env("CONTENT_LENGTH" , client->get_rq_body().size()));
env_vector.push_back(_dup_env("CONTENT_TYPE" , client->get_rq_headers("Content-Type")));
env_vector.push_back(_dup_env("GATEWAY_INTERFACE" , "CGI/1.1")); // https://www.rfc-editor.org/rfc/rfc3875#section-4.1.4
env_vector.push_back(_dup_env("PATH_INFO" , client->get_rq_script_info())); // LUKE: To Check
env_vector.push_back(_dup_env("PATH_TRANSLATED")); // not supported // LUKE: Why not supported ?
env_vector.push_back(_dup_env("PATH_INFO" , client->get_rq_script_info()));
env_vector.push_back(_dup_env("PATH_TRANSLATED")); // not used
env_vector.push_back(_dup_env("QUERY_STRING" , client->get_rq_query()));
env_vector.push_back(_dup_env("REMOTE_ADDR" , client->get_cl_ip()));
env_vector.push_back(_dup_env("REMOTE_HOST" , client->get_cl_ip())); // equal to REMOTE_ADDR or empty
env_vector.push_back(_dup_env("REMOTE_IDENT")); // authentification not supported
env_vector.push_back(_dup_env("REMOTE_USER")); // authentification not supported
env_vector.push_back(_dup_env("REQUEST_METHOD" , client->get_rq_method_str()));
env_vector.push_back(_dup_env("SCRIPT_NAME" , "/" + client->get_rq_script_path())); // LUKE: To Check
env_vector.push_back(_dup_env("SCRIPT_NAME" , "/" + client->get_rq_script_path()));
env_vector.push_back(_dup_env("SERVER_NAME" , client->get_cl_lsocket()->host));
env_vector.push_back(_dup_env("SERVER_PORT" , client->get_cl_lsocket()->port));
env_vector.push_back(_dup_env("SERVER_PROTOCOL" , "HTTP/1.1"));
@@ -279,15 +277,10 @@ void Webserv::_check_script_output(Client *client, std::string & output)
_check_script_status(client, output);
if (client->status >= 400 && client->status < 600)
return;
// /*DEBUG*/ std::cout << "\n" B_PURPLE "[script status]:\n" << "client->status:[" << client->status << "]" RESET "\n"; ::print_special(output); std::cout << B_PURPLE "-----------" RESET "\n\n";
client->status = _check_script_fields(output, client->status);
// /*DEBUG*/ std::cout << "\n" B_PURPLE "[script fields]:\n" << "client->status:[" << client->status << "]" RESET "\n"; ::print_special(output); std::cout << B_PURPLE "-----------" RESET "\n\n";
_check_fields_duplicates(client, output);
// /*DEBUG*/ std::cout << "\n" B_PURPLE "[fields duplicates]:\n" << "client->status:[" << client->status << "]" RESET "\n"; ::print_special(output); std::cout << B_PURPLE "-----------" RESET "\n\n";
_remove_body_leading_empty_lines(output);
// /*DEBUG*/ std::cout << "\n" B_PURPLE "[script empty lines]:\n" << "client->status:[" << client->status << "]" RESET "\n"; ::print_special(output); std::cout << B_PURPLE "-----------" RESET "\n\n";
_add_script_body_length_header(output);
// /*DEBUG*/ std::cout << "\n" B_PURPLE "[script content length]:\n" << "client->status:[" << client->status << "]" RESET "\n"; ::print_special(output); std::cout << B_PURPLE "-----------" RESET "\n\n";
}
void Webserv::_check_script_status(Client *client, std::string & output)
@@ -424,4 +417,3 @@ void Webserv::_add_script_body_length_header(std::string & output)
tmp += CRLF;
output.insert(0, tmp);
}

View File

@@ -7,13 +7,8 @@ void Webserv::_read_cgi_output(Client *client)
{
char buf[BUFSIZE];
ssize_t ret;
std::cerr << "_read_cgi_output()" << "\n"; // Debug
std::cerr << "cgi_pid = " << client->cgi_pid << "\n"; // Debug
std::cerr << "client fd = " << client->get_cl_fd() << "\n"; // Debug
std::cerr << "cgi fd = " << client->cgi_pipe_r_from_child << "\n"; // Debug
ret = ::read(client->cgi_pipe_r_from_child, buf, BUFSIZE);
std::cerr << "cgi read ret = " << ret << "\n"; // Debug
if (ret == -1)
{
std::perror("err read(cgi_fd)");
@@ -29,10 +24,6 @@ void Webserv::_read_cgi_output(Client *client)
void Webserv::_handle_epollerr_cgi_output(uint32_t events, Client *client)
{
(void)events;
std::cerr << "cgi EPOLLERR" << "\n";
std::cerr << "cgi_pid = " << client->cgi_pid << "\n";
std::cerr << "client fd = " << client->get_cl_fd() << "\n";
std::cerr << "cgi fd = " << client->cgi_pipe_r_from_child << "\n";
client->status = 500;
client->cgi_state = CGI_NO_CGI;
@@ -40,7 +31,6 @@ void Webserv::_handle_epollerr_cgi_output(uint32_t events, Client *client)
// Common with EPOLLHUP
pid_t wait_ret;
wait_ret = ::waitpid(client->cgi_pid, NULL, WNOHANG);
std::cerr << "cgi EPOLLERR waitpid ret = " << wait_ret << "\n";
if (wait_ret == client->cgi_pid)
{
_epoll_update(client->cgi_pipe_r_from_child, 0, EPOLL_CTL_DEL);
@@ -55,17 +45,10 @@ void Webserv::_handle_epollerr_cgi_output(uint32_t events, Client *client)
void Webserv::_handle_epollhup_cgi_output(uint32_t events, Client *client)
{
(void)events;
(void)client;
/* std::cerr << "cgi EPOLLHUP" << "\n";
std::cerr << "cgi_pid = " << client->cgi_pid << "\n";
std::cerr << "client fd = " << client->get_cl_fd() << "\n";
std::cerr << "cgi fd = " << client->cgi_pipe_r_from_child << "\n"; */
// Common with EPOLLERR
pid_t wait_ret;
wait_ret = ::waitpid(client->cgi_pid, NULL, WNOHANG);
// std::cerr << "cgi EPOLLHUP waitpid ret = " << wait_ret << "\n";
if (wait_ret == client->cgi_pid)
{
_epoll_update(client->cgi_pipe_r_from_child, 0, EPOLL_CTL_DEL);

View File

@@ -9,12 +9,10 @@ void Webserv::_close_client(int fd)
{
if (*it == fd)
{
// _epoll_update(fd, 0, EPOLL_CTL_DEL); // normalement superflu, DEBUG
std::cerr << "close client fd " << fd << "\n";
if (::close(fd) == -1)
std::perror("err close()");
_close_client_cgi_pipes(&(*it));
// it->clear(); // PISTE, debug normalement superflu
_clients.erase(it);
break;
}
@@ -48,15 +46,7 @@ void Webserv::_close_client_cgi_pipes(Client *client)
void Webserv::_close_all_clients()
{
_close_all_clients_fd();
_clients.clear();
// REMPLACEMENT ->
/* while (!_clients.empty())
{
std::cerr << "_clients.pop_back() " << &_clients.back() << "\n";
_clients.back().clear();
_clients.pop_back();
} */
}
void Webserv::_close_all_clients_fd()
@@ -66,7 +56,6 @@ void Webserv::_close_all_clients_fd()
std::vector<Client>::iterator it_end = _clients.end();
while (it != it_end)
{
// _epoll_update(_clients.back().fd, 0, EPOLL_CTL_DEL); // normalement superflu, DEBUG
std::cerr << "close client fd " << it->get_cl_fd() << "\n";
if (::close(it->get_cl_fd()) == -1)
std::perror("err close()");
@@ -80,7 +69,6 @@ void Webserv::_close_all_clients_cgi_pipes()
std::vector<Client>::iterator it_end = _clients.end();
while (it != it_end)
{
// _epoll_update(_clients.back().fd, 0, EPOLL_CTL_DEL); // normalement superflu, DEBUG
_close_client_cgi_pipes(&(*it));
++it;
}
@@ -91,7 +79,6 @@ void Webserv::_close_all_listen_sockets()
{ // TODO : change like clients (clear in place of pop_back)
while (!_listen_sockets.empty())
{
// _epoll_update(_listen_sockets.back().fd, 0, EPOLL_CTL_DEL); // normalement superflu, DEBUG
std::cerr << "close lsocket fd " << _listen_sockets.back().fd << "\n";
if (::close(_listen_sockets.back().fd) == -1)
std::perror("err close()");
@@ -99,11 +86,11 @@ void Webserv::_close_all_listen_sockets()
}
}
void Webserv::_reopen_lsocket(std::vector<listen_socket>::iterator it)
{
/*
** Many common code with init_virtual_servers(). Could refactor it.
*/
void Webserv::_reopen_lsocket(std::vector<listen_socket>::iterator it)
{
int ret;
std::cerr << "close lsocket " << it->fd << "\n";
@@ -119,9 +106,8 @@ void Webserv::_reopen_lsocket(std::vector<listen_socket>::iterator it)
}
it->fd = ret;
// HUGO ADD
// From : https://www.ibm.com/docs/en/i/7.2?topic=designs-example-nonblocking-io-select
// allow socket descriptor to be reuseable
// I just copied it from https://www.ibm.com/docs/en/i/7.2?topic=designs-example-nonblocking-io-select
int on = 1;
if (setsockopt(it->fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0)
{
@@ -129,7 +115,6 @@ void Webserv::_reopen_lsocket(std::vector<listen_socket>::iterator it)
_listen_sockets.erase(it);
return;
}
// HUGO ADD END
try {
_bind(it->fd, std::strtoul(it->port.c_str(), NULL, 10), it->host);
@@ -164,8 +149,5 @@ void Webserv::_handle_epoll_error_client(uint32_t events, int fd)
std::cerr << "EPOLLERR on client fd " << fd << "\n"; // DEBUG
if (events & EPOLLHUP)
std::cerr << "EPOLLHUP on client fd " << fd << "\n"; // DEBUG
if (std::find(_clients.begin(), _clients.end(), fd) != _clients.end())
std::cerr << "Found the client in _clients" << "\n"; // DEBUG
_close_client(fd); // " EPOLLHUP on client fd 8 " en boucle quand on mattraque un peu les CGI, donc il ne le trouve pas dans _clients. Etrange.
_close_client(fd);
}

View File

@@ -35,18 +35,14 @@ void Webserv::init_virtual_servers(std::vector<ServerConfig>* servers)
new_socket.port = it->port;
_listen_sockets.push_back(new_socket);
// HUGO ADD
//
// From : https://www.ibm.com/docs/en/i/7.2?topic=designs-example-nonblocking-io-select
// allow socket descriptor to be reuseable
// I just copied it from https://www.ibm.com/docs/en/i/7.2?topic=designs-example-nonblocking-io-select
int on = 1;
if (setsockopt(new_socket.fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0)
if (setsockopt(new_socket.fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0)
{
::perror("err setsockopt()");
throw std::runtime_error("Socket init");
}
//
// HUGO ADD END
_bind(new_socket.fd, std::strtoul(it->port.c_str(), NULL, 10), it->host);
_listen(new_socket.fd, 42); // 42 arbitrary
@@ -69,7 +65,6 @@ void Webserv::_bind(int socket_fd, in_port_t port, std::string host)
addr.sin_family = AF_INET;
addr.sin_port = ::htons(port);
addr.sin_addr.s_addr = ::htonl(::inet_addr(host.c_str()));
// addr.sin_addr.s_addr = ::htonl(INADDR_ANY); // htonl useless with 0 value (INADDR_ANY) ?
if (::bind(socket_fd, (const sockaddr*)&addr, sizeof addr) == -1)
{

View File

@@ -2,7 +2,6 @@
#include "Webserv.hpp"
#define MAX_FILESIZE 1 * MB // unused
// const?
/*
https://www.rfc-editor.org/rfc/rfc9110.html#name-get
*/
@@ -84,7 +83,11 @@ if (size > MAX_FILESIZE)
*/
// const?
/*
<a href="http://nginx.org/">nginx.org</a>.<br/>
<a href="/test/test_deeper/index1.html">index1.html</a>
<a href="/test/test_deeper/..">..</a>
*/
void Webserv::_autoindex(Client *client, const std::string &path)
{
std::cout << "_autoindex()\n";
@@ -93,7 +96,6 @@ void Webserv::_autoindex(Client *client, const std::string &path)
DIR *dir;
struct dirent *ent;
// std::cout << "Path in auto is: " << path << '\n';
if ( (dir = opendir(path.c_str()) ) != NULL)
{
dir_list.append(AUTOINDEX_START);
@@ -117,13 +119,6 @@ void Webserv::_autoindex(Client *client, const std::string &path)
dir_list.append("</a>");
dir_list.append("\n");
}
// <a href="http://nginx.org/">nginx.org</a>.<br/>
// <a href="/test/test_deeper/index1.html">index1.html</a>
// apparently this is more than good enough!
// <a href="/test/test_deeper/..">..</a>
dir_list.append(AUTOINDEX_END);
closedir (dir);
client->status = 200;

View File

@@ -8,16 +8,14 @@ void Webserv::_post(Client *client, const std::string &path)
{
(void)path; // unused, we use "assigned_location->upload_dir" instead
std::cout << "_post()\n";
std::cerr << "upload_dir = " << client->assigned_location->upload_dir << "\n";
if (client->get_rq_abs_path() != client->assigned_location->path)
client->status = 404; // 404 ? J'ai un doute.
client->status = 404; // 404 or other status better ?
else if (client->assigned_location->upload_dir.empty())
client->status = 404; // 404 ? J'ai un doute.
client->status = 404; // 404 or other status better ?
else if (client->get_rq_multi_bodys().empty())
{
client->status = 415;
client->status = 415; // Unsupported Media Type
client->response.append("Accept: multipart/form-data"); // empty, no encoding accepted
client->response.append(CRLF);
}
@@ -25,7 +23,7 @@ void Webserv::_post(Client *client, const std::string &path)
_upload_files(client);
}
// #include <ctime> // could add date to DEFAULT_NAME to avoid overwriting files
// #include <ctime> // TODO: could add date to DEFAULT_NAME to avoid overwriting files
#define DEFAULT_NAME "unnamed_file"
void Webserv::_upload_files(Client *client)
{
@@ -58,7 +56,7 @@ void Webserv::_upload_files(Client *client)
{
filename = filename.substr(pos + sizeof("filename=")-1);
std::cerr << "filename ="<< filename << "\n";
// A l'arrache pour enlever les "
// Pour enlever les "
filename.erase(0, 1);
std::cerr << "filename ="<< filename << "\n";
filename.erase(filename.size()-1, 1);
@@ -69,7 +67,7 @@ void Webserv::_upload_files(Client *client)
filename = DEFAULT_NAME + ::itos(i_name++);
std::cerr << "filename ="<< filename << "\n";
path = client->assigned_location->upload_dir; // Assume there a final '/'
path = client->assigned_location->upload_dir;
path.append(filename);
@@ -78,7 +76,6 @@ void Webserv::_upload_files(Client *client)
else
file_existed = true;
// How to determine status 403 for file that dont already exist ? access() on the upload_dir ?
if (file_existed && ::access(path.c_str(), W_OK) == -1)
{
std::perror("err access()");

View File

@@ -36,22 +36,15 @@ int Webserv::_read_request(Client *client)
ssize_t ret;
ret = ::recv(client->get_cl_fd(), buf, BUFSIZE, 0);
std::cerr << "recv() on fd(" << client->get_cl_fd() << ") returned = " << ret << "\n" ;
std::cerr << "recv() on fd(" << client->get_cl_fd() << ") ret = " << ret << "\n" ;
if (ret == -1)
{
std::perror("err recv()");
return READ_CLOSE;
}
if (ret == 0)
{
std::cerr << "recv() read 0, then close client" << "\n"; // DEBUG
return READ_CLOSE;
}
client->raw_request.append(buf, ret);
// ::print_special(client->raw_request);
// std::cerr << "__raw_request__\n" << client->raw_request << "\n______\n"; // DEBUG
// print_special(client->raw_request);
if (!client->header_complete)
{
@@ -73,7 +66,6 @@ int Webserv::_read_request(Client *client)
}
if (client->header_complete)
{
// client->read_body_size += ret; // Not accurate, part of body could have been read with headers, unused for now
client->parse_request_body();
if (client->status || client->body_complete)
return READ_COMPLETE;

View File

@@ -22,10 +22,9 @@ void Webserv::_response(Client *client)
else if (ret == SEND_COMPLETE)
{
if (client->get_rq_headers("Connection") == "close"
|| client->status == 400 // TODO: Refactoring
|| client->status == 400
|| client->status == 408
|| client->status == 413)
// || client->cgi_state == CGI_OUTPUT_COMPLETE) // DEBUG
_close_client(client->get_cl_fd());
else
{
@@ -42,9 +41,7 @@ int Webserv::_send_response(Client *client)
std::cerr << "send()\n";
if (client->response.empty())
{
_append_base_headers(client);
}
if (!client->status)
{
@@ -58,34 +55,27 @@ int Webserv::_send_response(Client *client)
if (client->status >= 400)
_error_html_response(client);
// /*DEBUG*/ std::cout << "\n" B_PURPLE "[response + output + headers]:" RESET "\n"; ::print_special(client->response); std::cout << "\n" B_PURPLE "-----------" RESET "\n\n";
// /* Debug */ std::cerr << "client->response.size() = " << client->response.size() << "\n"; // DEBUG
ret = ::send(client->get_cl_fd(), client->response.c_str(), client->response.size(), 0);
if (ret == -1)
{
std::perror("err send()");
std::cerr << "client.fd =" << client->get_cl_fd() << "\n"; // DEBUG
return SEND_CLOSE;
}
if (ret == 0) // actually never happen ?
if (ret == 0)
{
std::cerr << "SEND RET 0 for client.fd =" << client->get_cl_fd() << "\n"; // DEBUG
std::cerr << "send() ret == 0 never happens ?" << "\n"; // Debug
return SEND_CLOSE;
}
// /* Debug */ std::cerr << "ret send() = " << ret << "\n"; // DEBUG
return SEND_COMPLETE;
}
void Webserv::_append_base_headers(Client *client)
{
std::cerr << "_append_base_headers()\n"; // debug
client->response.append("Server: Webserv/0.1" CRLF);
if (client->get_rq_headers("Connection") == "close"
|| client->status == 400 // TODO: Refactoring
|| client->status == 400
|| client->status == 408
|| client->status == 413)
client->response.append("Connection: close" CRLF);
@@ -97,7 +87,7 @@ void Webserv::_construct_response(Client *client)
{
std::string path;
std::string script_output;
path = _replace_url_root(client, client->get_rq_abs_path());
if (client->cgi_state == CGI_READY_TO_EXEC)
{
@@ -108,13 +98,9 @@ void Webserv::_construct_response(Client *client)
}
else if (client->cgi_state == CGI_OUTPUT_COMPLETE)
{
// /*DEBUG*/ std::cout << "\n" B_PURPLE "[response]:" RESET "\n"; ::print_special(client->response); std::cout << B_PURPLE "-----------" RESET "\n\n";
// /*DEBUG*/ std::cout << "\n" B_PURPLE "[script output]:" RESET "\n"; ::print_special(client->cgi_output); std::cout << B_PURPLE "-----------" RESET "\n\n";
_check_script_output(client, client->cgi_output); // FD_CGI : adjust for client->cgi_output;
_check_script_output(client, client->cgi_output);
if (client->status < 400 || client->status >= 600)
client->response += client->cgi_output;
// client->cgi_state = CGI_NO_CGI; // Not indispensable, reset when client.clear()
// /*DEBUG*/ std::cout << "\n" B_PURPLE "[response + output]:" RESET "\n"; ::print_special(client->response); std::cout << B_PURPLE "-----------" RESET "\n\n";
}
else if (_is_cgi(client, path))
_cgi_open_pipes(client);
@@ -124,9 +110,6 @@ void Webserv::_construct_response(Client *client)
void Webserv::_process_method(Client *client, std::string &path)
{
// std::cerr << "allow_methods = " << http_methods_to_str(client->assigned_location->allow_methods) << "\n"; // debug
std::cerr << "Path again: " << path << '\n'; // debug
switch (client->get_rq_method())
{
case (GET):
@@ -142,13 +125,10 @@ void Webserv::_process_method(Client *client, std::string &path)
std::string Webserv::_replace_url_root(Client *client, std::string path)
{
// /* Debug */ std::cerr << "assigned_location->path = " << client->assigned_location->path << "\n"; // debug
// /* Debug */ std::cerr << "path before = " << path << "\n"; // DEBUG
if (client->assigned_location->path == "/")
path.insert(0, client->assigned_location->root);
else
path.replace(0, client->assigned_location->path.size(), client->assigned_location->root);
// /* Debug */ std::cerr << "path after = " << path << "\n"; // DEBUG
return path;
}
@@ -212,4 +192,3 @@ void Webserv::_append_body(Client *client, const std::string &body, const std::s
client->response.append(CRLF);
client->response.append(body);
}

View File

@@ -16,6 +16,8 @@ void Webserv::run()
Client *client_cgi_input = NULL;
Client *client_cgi_output = NULL;
std::signal(SIGPIPE, signal_handler);
std::signal(SIGINT, signal_handler);
g_run = true;
while (g_run)
{
@@ -29,7 +31,11 @@ void Webserv::run()
if (errno_copy == EINTR)
g_run = false;
else
{
std::signal(SIGPIPE, SIG_DFL);
std::signal(SIGINT, SIG_DFL);
throw std::runtime_error("Epoll wait");
}
}
else if (nfds == 0 && !_clients.empty())
_timeout();
@@ -101,4 +107,6 @@ void Webserv::run()
}
}
}
std::signal(SIGPIPE, SIG_DFL);
std::signal(SIGINT, SIG_DFL);
}

View File

@@ -14,16 +14,10 @@ void Webserv::_handle_last_signal()
if (g_last_signal == SIGPIPE)
{
std::cerr << "SIGPIPE\n";
// if (_actual_client)
// {
// _close_client(_actual_client->fd);
// _actual_client = NULL;
// }
}
else if (g_last_signal == SIGINT)
{
g_run = false;
// maybe a throw here instead of "g_run" ?
}
g_last_signal = 0;
}

View File

@@ -12,12 +12,7 @@ void Webserv::_timeout()
std::cerr << "timeout request fd " << it->get_cl_fd() << "\n";
it->status = 408;
_epoll_update(it->get_cl_fd(), EPOLLOUT, EPOLL_CTL_MOD);
// DEBUG, close without repsonse 408
/* _close_client(it->get_cl_fd());
it = _clients.begin(); */
}
// else // DEBUG
++it;
}
}