From cf6f356cef54e3473561620523f2924776679385 Mon Sep 17 00:00:00 2001 From: Talyx Date: Fri, 18 Feb 2022 20:23:01 +0300 Subject: [PATCH] add: sig handler --- Makefile | 4 ++-- includes/webserv.hpp | 1 + src/Server/Server.cpp | 16 ++++++++++++---- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 093fc02..29fbb8f 100644 --- a/Makefile +++ b/Makefile @@ -2,9 +2,9 @@ NAME = webserv CXX = clang++ -SANFLAGS = -fsanitize=address +# SANFLAGS = -fsanitize=address -# SANFLAGS = -fsanitize=leak +SANFLAGS = -fsanitize=leak DEBUGFLAGS = -g -fno-limit-debug-info diff --git a/includes/webserv.hpp b/includes/webserv.hpp index e63c9d3..7074b52 100644 --- a/includes/webserv.hpp +++ b/includes/webserv.hpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include diff --git a/src/Server/Server.cpp b/src/Server/Server.cpp index de7bdd0..e7ae52f 100644 --- a/src/Server/Server.cpp +++ b/src/Server/Server.cpp @@ -188,6 +188,12 @@ void Server::add_to_epoll_list(int fd, unsigned int ep_events) << ENDL; } +void sigHandler(int sig) +{ + if (sig == SIGINT) + throw ConfigException("SIGINT called. Server shutdown!"); +} + void Server::start(void) { /* Socket server_sock(AF_INET, SOCK_STREAM, 0, _port, "127.0.0.1"); */ @@ -198,7 +204,8 @@ void Server::start(void) unsigned int client_events = EPOLLIN; unsigned int server_events = EPOLLIN; - + + std::signal(SIGINT, sigHandler); _epoll_fd = epoll_create(1337); @@ -301,6 +308,7 @@ void Server::start(void) if (client_map[fd]->allSended()) { delete_client(client_map, fd); + // throw ConfigException("END!"); } } } @@ -428,9 +436,9 @@ void Server::clean_parsed(TOMLMap *root) DBOUT << ">>> cleaning up: <<<" << std::endl; for (it = root->begin(); it != root->end(); ++it) { - DBOUT << RED << it->first - << ": " << GREEN - << *(it->second->toString()); + // DBOUT << RED << it->first + // << ": " << GREEN + // << *(it->second->toString()); clean_generic(it->second); /* delete it->second; */