Skip to content

Commit

Permalink
feat: included signal handling to stop the server
Browse files Browse the repository at this point in the history
need to check because what I really need to use sigpipe
  • Loading branch information
0bvim committed Jul 3, 2024
1 parent 7b08665 commit dca00dd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 6 additions & 1 deletion include/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: bmoretti <bmoretti@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/27 11:24:48 by bmoretti #+# #+# */
/* Updated: 2024/07/01 13:50:18 by bmoretti ### ########.fr */
/* Updated: 2024/07/03 12:48:13 by vde-frei ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -28,6 +28,8 @@
# include <unistd.h>

// C++ LIBS
# include <cstring>
# include <csignal>
# include <iostream>
# include <stdexcept>
# include <string>
Expand All @@ -47,6 +49,9 @@
# define BROWN(text) "\033[33m" << text << "\033[0m"
# define WHITE(text) "\033[37m" << text << "\033[0m"
# define BLACK(text) "\033[30m" << text << "\033[0m"
# define OUTNL(text) std::cout << text << std::endl
# define OUT(text) std::cout << text
# define NL std::cout << std::endl

# define BG_BLUE(text) "\033[44m" << text << "\033[0m"
# define BG_RED(text) "\033[41m" << text << "\033[0m"
Expand Down
13 changes: 12 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
# include "Server.hpp"
#include <cstring>

bool g_sigint = false;

void handle_signal(int c)
{
(void)c;
g_sigint = true;
OUTNL(RED("\r[HALT]: STOPPING THE SERVER... \n"));
}

int main(void)
{
signal(SIGPIPE, SIG_IGN);
signal(SIGINT, handle_signal);

try {
Server serv;
}
Expand Down

0 comments on commit dca00dd

Please sign in to comment.