lots of log message and fixed bad_file_descriptor issue

This commit is contained in:
hugogogo
2022-08-22 01:50:28 +02:00
parent 469eca8aa9
commit 5225e3258b
18 changed files with 186 additions and 112 deletions

View File

@@ -9,7 +9,7 @@ void Webserv::_close_client(int fd)
{
if (*it == fd)
{
std::cerr << "close client fd " << fd << "\n";
std::cout << family << "| (" << std::setw(2) << it->get_cl_fd() << ") close client fd " << fd << std::endl;
if (::close(fd) == -1)
std::perror("err close()");
_close_client_cgi_pipes(&(*it));
@@ -24,21 +24,28 @@ void Webserv::_close_client_cgi_pipes(Client *client)
{
if (client->cgi_state)
{ // No need to reset the fd to -1 normaly
std::cerr << "close cgi-pipes" << "\n";
if (::close(client->cgi_pipe_w_to_child) == -1)
std::perror("err close()");
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") close pipe wtc [" << client->cgi_pipe_w_to_child << "]\n";
if (client->cgi_pipe_w_to_child != -1)
if (::close(client->cgi_pipe_w_to_child) == -1)
std::perror("err close()");
client->cgi_pipe_w_to_child = -1;
if (::close(client->cgi_pipe_r_from_child) == -1)
std::perror("err close()");
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") close pipe rfc [" << client->cgi_pipe_r_from_child << "]\n";
if (client->cgi_pipe_r_from_child != -1)
if (::close(client->cgi_pipe_r_from_child) == -1)
std::perror("err close()");
client->cgi_pipe_r_from_child = -1;
if (::close(client->cgi_pipe_w_to_parent) == -1)
std::perror("err close()");
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") close pipe wtp [" << client->cgi_pipe_w_to_parent << "]\n";
if (client->cgi_pipe_w_to_parent != -1)
if (::close(client->cgi_pipe_w_to_parent) == -1)
std::perror("err close()");
client->cgi_pipe_w_to_parent = -1;
if (::close(client->cgi_pipe_r_from_parent) == -1)
std::perror("err close()");
std::cerr << family << "| (" << std::setw(2) << client->get_cl_fd() << ") close pipe rfp [" << client->cgi_pipe_r_from_parent << "]\n";
if (client->cgi_pipe_r_from_parent != -1)
if (::close(client->cgi_pipe_r_from_parent) == -1)
std::perror("err close()");
client->cgi_pipe_r_from_parent = -1;
}
}
@@ -56,7 +63,7 @@ void Webserv::_close_all_clients_fd()
std::vector<Client>::iterator it_end = _clients.end();
while (it != it_end)
{
std::cerr << "close client fd " << it->get_cl_fd() << "\n";
std::cout << family << "| (" << std::setw(2) << it->get_cl_fd() << ") close client fd " << it->get_cl_fd() << std::endl;
if (::close(it->get_cl_fd()) == -1)
std::perror("err close()");
++it;