」 feat: added ctrl c handling

This commit is contained in:
2025-04-22 15:41:35 +02:00
parent 5d1c3910bc
commit 701401f559
4 changed files with 21 additions and 6 deletions

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/14 12:53:54 by adjoly #+# #+# */
/* Updated: 2025/04/22 15:32:19 by adjoly ### ########.fr */
/* Updated: 2025/04/22 15:35:52 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -35,6 +35,7 @@ Config::Config(std::string &filename) {
std::map<std::string, toml::ANode *> *node = table->getTable();
for (auto it = prange(node)) {
if (it->second->type() == toml::TABLE) {
_log->info("taking server from table : " + it->first);
Server *srv = new Server(it->second);
_servers.push_back(srv);
}

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/24 15:10:07 by adjoly #+# #+# */
/* Updated: 2025/04/22 15:25:06 by adjoly ### ########.fr */
/* Updated: 2025/04/22 15:36:30 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -79,7 +79,7 @@ Server::Server(toml::ANode *node) : _table(node) {
(*_routes)[URL(it->first)] = new Route(it->second);
}
}
delete _table;
//delete _table;
}
Server::~Server(void) {

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/03 15:45:07 by mmoussou #+# #+# */
/* Updated: 2025/04/22 14:52:44 by adjoly ### ########.fr */
/* Updated: 2025/04/22 15:39:43 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,6 +18,7 @@
#include <exception>
#include <help.hpp>
#include <requests/default.hpp>
#include <sstream>
#include <tomlpp.hpp>
#include <unistd.h>
#include <log.hpp>
@ -31,6 +32,10 @@ int _sig = 0;
void ft_sig(int sig) {
_sig = sig;
std::stringstream str;
str << "sig hitted = ";
str << sig;
_log->info(str.str());
}
int main(int ac, char **av) {

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/11 16:11:40 by adjoly #+# #+# */
/* Updated: 2025/04/22 10:51:15 by adjoly ### ########.fr */
/* Updated: 2025/04/22 15:40:59 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -28,6 +28,8 @@
using namespace webserv;
extern int _sig;
std::string convertIPToString(const struct in_addr *addr) {
unsigned int ip = ntohl(addr->s_addr);
std::stringstream ss;
@ -77,6 +79,13 @@ void Server::_setup(void) {
}
}
short sigHandling(void) {
if (_sig == SIGINT) {
return 727;
}
return 0;
}
void Server::_run(void) {
struct pollfd fd;
@ -89,7 +98,7 @@ void Server::_run(void) {
}
// to add signal instead of 727
while (727) {
while (727 - sigHandling()) {
if (poll(_client_fds.data(), _client_fds.size(), -1) < 0) {
std::stringstream str;
str << "poll failed : ";