diff --git a/sources/core/Server.cpp b/sources/core/Server.cpp index 7b0609f..48f7e5b 100644 --- a/sources/core/Server.cpp +++ b/sources/core/Server.cpp @@ -6,7 +6,7 @@ /* By: sben-tay +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/13 11:11:07 by rparodi #+# #+# */ -/* Updated: 2025/06/23 13:00:50 by rparodi ### ########.fr */ +/* Updated: 2025/06/23 14:39:03 by sben-tay ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,6 +23,15 @@ #include #include #include +#include + +volatile sig_atomic_t g_stop = 0; + +void handle_sigint(int sig) { + (void)sig; + g_stop = 1; +} + /** * @brief The constructor of the Server class. @@ -53,6 +62,7 @@ std::vector splitLines(const std::string& input); void Server::start() { + signal(SIGINT, handle_sigint); _serverFd = socket(AF_INET, SOCK_STREAM, 0); if (_serverFd == -1) { ERROR_MSG("Error in the socket function"); @@ -79,7 +89,7 @@ void Server::start() std::vector > readyClients; std::vector readyToWrite; - while (true) { + while (!g_stop) { printUsers(); newClients.clear(); @@ -136,7 +146,7 @@ void Server::start() std::cout << "Poll loop finished" << std::endl; } - + std::cout << "[INFO] CTRL+C détecté. Fermeture du serveur..." << std::endl; close(_serverFd); } diff --git a/sources/core/main.cpp b/sources/core/main.cpp index 269b649..8fd050b 100644 --- a/sources/core/main.cpp +++ b/sources/core/main.cpp @@ -3,15 +3,19 @@ /* ::: :::::::: */ /* main.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: omoudni +#+ +:+ +#+ */ +/* By: sben-tay +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/13 11:03:13 by rparodi #+# #+# */ -/* Updated: 2025/05/19 15:02:41 by omoudni ### ########.fr */ +/* Updated: 2025/06/23 14:38:53 by sben-tay ### ########.fr */ /* */ /* ************************************************************************** */ #include "core.hpp" #include +#include "server.hpp" +#include + + int main(int argc, char *argv[]) { Parser parser(argc, argv);