add: sig handler

This commit is contained in:
Talyx
2022-02-18 20:23:01 +03:00
parent 1519914e97
commit cf6f356cef
3 changed files with 15 additions and 6 deletions

View File

@@ -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

View File

@@ -31,6 +31,7 @@
#include <arpa/inet.h>
#include <wait.h>
#include <exception>
#include <csignal>
#include <netinet/in.h>
#include <fcntl.h>

View File

@@ -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"); */
@@ -199,6 +205,7 @@ 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; */