fixed poll bug when exiting with ctrl+C
This commit is contained in:
2
Makefile
2
Makefile
@@ -6,7 +6,7 @@ OBJ = ${SRC:.cpp=.o}
|
||||
|
||||
CXX = c++
|
||||
|
||||
CXXFLAGS = -std=c++98 #-fsanitize=address -g3 #-Wall -Wextra -Werror
|
||||
CXXFLAGS = -std=c++98 -fsanitize=address -g3 #-Wall -Wextra -Werror
|
||||
|
||||
all : $(NAME)
|
||||
|
||||
|
@@ -50,14 +50,14 @@ void Server::init() {
|
||||
signal(SIGQUIT, receiveSignal);
|
||||
|
||||
createServerSocket();
|
||||
std::cout << ">>> SERVER STARTED <<<" << std::endl;
|
||||
std::cout << "Waiting for connections..." << std::endl;
|
||||
std::cout << GREEN << ">>> SERVER STARTED <<<" << RESET << std::endl;
|
||||
std::cout << CYAN <<"Waiting for connections..." << RESET << std::endl;
|
||||
}
|
||||
|
||||
void Server::run() {
|
||||
while (!_signal) {
|
||||
int ret = poll(&_fds[0], _fds.size(), -1);
|
||||
if (ret == -1)
|
||||
if (ret == -1 && !_signal)
|
||||
throw std::runtime_error("Error: poll() failed");
|
||||
|
||||
for (size_t i = 0; i < _fds.size(); ++i) {
|
||||
|
@@ -21,7 +21,13 @@
|
||||
#include <ctime>
|
||||
#include <iomanip>
|
||||
#define BUFFER_SIZE 1024
|
||||
|
||||
#define RED "\033[31m"
|
||||
#define GREEN "\033[32m"
|
||||
#define YELLOW "\033[33m"
|
||||
#define BLUE "\033[34m"
|
||||
#define MAGENTA "\033[35m"
|
||||
#define CYAN "\033[36m"
|
||||
#define RESET "\033[0m"
|
||||
|
||||
class Server {
|
||||
private:
|
||||
|
Reference in New Issue
Block a user