mirror of
https://github.com/3lswear/webserv.git
synced 2025-10-28 21:07:59 +03:00
feat: delete when empty
This commit is contained in:
@@ -114,6 +114,20 @@ void Server::readSocket(Client &client, int fd)
|
||||
DBOUT << BLUE << "status is " << Response::getReasonPhrase(status) << RESET << std::endl;
|
||||
bzero(buf, BUFFSIZE);
|
||||
}
|
||||
int Server::delete_client(std::map<int,Client *> &client_map, int fd)
|
||||
{
|
||||
int ret;
|
||||
ret = epoll_ctl(_epoll_fd, EPOLL_CTL_DEL, fd, NULL);
|
||||
close(fd);
|
||||
client_map[fd]->clear();
|
||||
delete (client_map[fd]);
|
||||
client_map.erase(fd);
|
||||
DBOUT << RED <<
|
||||
"deleting client "
|
||||
<< fd
|
||||
<< ENDL;
|
||||
return (ret);
|
||||
}
|
||||
|
||||
void Server::setupConfig(void)
|
||||
{
|
||||
@@ -202,6 +216,8 @@ void Server::start(void)
|
||||
assert( epoll_ctl(_epoll_fd, EPOLL_CTL_MOD, fd, &ev) == 0);
|
||||
DBOUT << GREEN << "rearmed to EPOLLOUT" << ENDL;
|
||||
}
|
||||
if (client_map[fd]->isEmpty())
|
||||
delete_client(client_map, fd);
|
||||
}
|
||||
else if (events & EPOLLOUT)
|
||||
{
|
||||
@@ -210,15 +226,7 @@ void Server::start(void)
|
||||
sendData(*client_map[fd], fd);
|
||||
if (client_map[fd]->allSended())
|
||||
{
|
||||
epoll_ctl(_epoll_fd, EPOLL_CTL_DEL, fd, NULL);
|
||||
close(fd);
|
||||
client_map[fd]->clear();
|
||||
delete (client_map[fd]);
|
||||
client_map.erase(fd);
|
||||
DBOUT << RED <<
|
||||
"deleting client "
|
||||
<< fd
|
||||
<< ENDL;
|
||||
delete_client(client_map, fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ class Server
|
||||
void setNonBlock(int fd);
|
||||
void sendData(Client &client, int fd);
|
||||
void readSocket(Client &client, int fd);
|
||||
int delete_client(std::map<int,Client *> &map, int fd);
|
||||
|
||||
enum e_req_status
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user