Fixed, close() forgottens fds after fork

+ minors changes
+ Super new epoll loop output :)
This commit is contained in:
lperrey
2022-08-17 01:49:31 +02:00
parent ccc542f52b
commit 9f3903d497
4 changed files with 65 additions and 25 deletions

View File

@@ -28,6 +28,7 @@ void Webserv::_close_all_clients()
void Webserv::_close_all_clients_fd()
{
_close_all_clients_cgi_fd();
std::vector<Client>::iterator it = _clients.begin();
std::vector<Client>::iterator it_end = _clients.end();
while (it != it_end)
@@ -40,6 +41,24 @@ void Webserv::_close_all_clients_fd()
}
}
void Webserv::_close_all_clients_cgi_fd()
{
std::vector<Client>::iterator it = _clients.begin();
std::vector<Client>::iterator it_end = _clients.end();
while (it != it_end)
{
// _epoll_update(_clients.back().fd, 0, EPOLL_CTL_DEL); // normalement superflu, DEBUG
if (it->cgi_pipe_rfd)
{
std::cerr << "close cgi-fd " << it->cgi_pipe_rfd << "\n";
if (::close(it->cgi_pipe_rfd) == -1)
std::perror("err close()");
}
++it;
}
}
void Webserv::_close_all_listen_sockets()
{ // TODO : change like clients (clear in place of pop_back)
while (!_listen_sockets.empty())
@@ -117,5 +136,8 @@ 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
_close_client(fd);
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.
}