handled signals

This commit is contained in:
bettercallous
2024-04-08 07:40:49 +00:00
parent 2fdb0eb6c4
commit 614f631723
3 changed files with 21 additions and 1 deletions

View File

@@ -1,5 +1,7 @@
#include "Server.hpp" #include "Server.hpp"
bool Server::_signal = false;
Server::Server() {} Server::Server() {}
Server::~Server() {} Server::~Server() {}
@@ -22,3 +24,16 @@ void Server::parseArgs(int ac, char **av) {
this->_port = _port; this->_port = _port;
this->_password = pwd; this->_password = pwd;
} }
void Server::receiveSignal(int signum) {
_signal = true;
(void)signum;
}
void Server::init() {
signal(SIGINT, receiveSignal);
signal(SIGQUIT, receiveSignal);
std::cout << ">>> SERVER STARTED <<<" << std::endl;
std::cout << "Waiting for connections..." << std::endl;
}

View File

@@ -1,19 +1,23 @@
#ifndef SERVER_HPP #ifndef SERVER_HPP
#define SERVER_HPP #define SERVER_HPP
#include <iostream> #include <iostream>
#include <cstdlib> #include <cstdlib>
#include <csignal>
class Server { class Server {
private: private:
int _port; int _port;
static bool _signal;
std::string _password; std::string _password;
public: public:
Server(); Server();
~Server(); ~Server();
void parseArgs(int ac, char **av); void parseArgs(int ac, char **av);
static void receiveSignal(int signum);
void init();
}; };
#endif #endif

View File

@@ -6,6 +6,7 @@ int main(int ac, char **av)
try { try {
server.parseArgs(ac, av); server.parseArgs(ac, av);
server.init();
} catch (std::exception& e) { } catch (std::exception& e) {
std::cerr << e.what() << std::endl; std::cerr << e.what() << std::endl;
return 1; return 1;