commit
5ea6ef151b
2 changed files with 19 additions and 5 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/05/13 11:11:07 by rparodi #+# #+# */
|
/* 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 <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
volatile sig_atomic_t g_stop = 0;
|
||||||
|
|
||||||
|
void handle_sigint(int sig) {
|
||||||
|
(void)sig;
|
||||||
|
g_stop = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The constructor of the Server class.
|
* @brief The constructor of the Server class.
|
||||||
|
|
@ -53,6 +62,7 @@ std::vector<std::string> splitLines(const std::string& input);
|
||||||
|
|
||||||
void Server::start()
|
void Server::start()
|
||||||
{
|
{
|
||||||
|
signal(SIGINT, handle_sigint);
|
||||||
_serverFd = socket(AF_INET, SOCK_STREAM, 0);
|
_serverFd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if (_serverFd == -1) {
|
if (_serverFd == -1) {
|
||||||
ERROR_MSG("Error in the socket function");
|
ERROR_MSG("Error in the socket function");
|
||||||
|
|
@ -79,7 +89,7 @@ void Server::start()
|
||||||
std::vector<std::pair<int, std::string > > readyClients;
|
std::vector<std::pair<int, std::string > > readyClients;
|
||||||
std::vector<int> readyToWrite;
|
std::vector<int> readyToWrite;
|
||||||
|
|
||||||
while (true) {
|
while (!g_stop) {
|
||||||
printUsers();
|
printUsers();
|
||||||
|
|
||||||
newClients.clear();
|
newClients.clear();
|
||||||
|
|
@ -136,7 +146,7 @@ void Server::start()
|
||||||
|
|
||||||
std::cout << "Poll loop finished" << std::endl;
|
std::cout << "Poll loop finished" << std::endl;
|
||||||
}
|
}
|
||||||
|
std::cout << "[INFO] CTRL+C détecté. Fermeture du serveur..." << std::endl;
|
||||||
close(_serverFd);
|
close(_serverFd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,19 @@
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* main.cpp :+: :+: :+: */
|
/* main.cpp :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: omoudni <omoudni@student.42paris.fr> +#+ +:+ +#+ */
|
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/05/13 11:03:13 by rparodi #+# #+# */
|
/* 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 "core.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "server.hpp"
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
Parser parser(argc, argv);
|
Parser parser(argc, argv);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue