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++ CXX = clang++
SANFLAGS = -fsanitize=address # SANFLAGS = -fsanitize=address
# SANFLAGS = -fsanitize=leak SANFLAGS = -fsanitize=leak
DEBUGFLAGS = -g -fno-limit-debug-info DEBUGFLAGS = -g -fno-limit-debug-info

View File

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

View File

@@ -188,6 +188,12 @@ void Server::add_to_epoll_list(int fd, unsigned int ep_events)
<< ENDL; << ENDL;
} }
void sigHandler(int sig)
{
if (sig == SIGINT)
throw ConfigException("SIGINT called. Server shutdown!");
}
void Server::start(void) void Server::start(void)
{ {
/* Socket server_sock(AF_INET, SOCK_STREAM, 0, _port, "127.0.0.1"); */ /* 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 client_events = EPOLLIN;
unsigned int server_events = EPOLLIN; unsigned int server_events = EPOLLIN;
std::signal(SIGINT, sigHandler);
_epoll_fd = epoll_create(1337); _epoll_fd = epoll_create(1337);
@@ -301,6 +308,7 @@ void Server::start(void)
if (client_map[fd]->allSended()) if (client_map[fd]->allSended())
{ {
delete_client(client_map, fd); delete_client(client_map, fd);
// throw ConfigException("END!");
} }
} }
} }
@@ -428,9 +436,9 @@ void Server::clean_parsed(TOMLMap *root)
DBOUT << ">>> cleaning up: <<<" << std::endl; DBOUT << ">>> cleaning up: <<<" << std::endl;
for (it = root->begin(); it != root->end(); ++it) for (it = root->begin(); it != root->end(); ++it)
{ {
DBOUT << RED << it->first // DBOUT << RED << it->first
<< ": " << GREEN // << ": " << GREEN
<< *(it->second->toString()); // << *(it->second->toString());
clean_generic(it->second); clean_generic(it->second);
/* delete it->second; */ /* delete it->second; */