close fds and exit the program cleanly
This commit is contained in:
14
Server.cpp
14
Server.cpp
@@ -54,6 +54,7 @@ void Server::run() {
|
||||
}
|
||||
}
|
||||
}
|
||||
closeFds();
|
||||
}
|
||||
|
||||
void Server::createServerSocket() {
|
||||
@@ -163,3 +164,16 @@ void Server::clientCleanup(int fd) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Server::closeFds() {
|
||||
for (size_t i = 0; i < _clients.size(); i++){
|
||||
int fd = _clients[i].getFd();
|
||||
std::cout << "Client <" << fd << "> Disconnected" << std::endl;
|
||||
close(fd);
|
||||
}
|
||||
|
||||
if (_serverSocketFd != -1)
|
||||
close(_serverSocketFd);
|
||||
|
||||
_fds.clear();
|
||||
}
|
@@ -35,6 +35,7 @@ class Server {
|
||||
void handleClientConnection();
|
||||
void handleClientData(int fd);
|
||||
void clientCleanup(int fd);
|
||||
void closeFds();
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user