clean comment and stuff
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user