diff --git a/inc/Server.hpp b/inc/Server.hpp index 5fe9b03..61a078a 100644 --- a/inc/Server.hpp +++ b/inc/Server.hpp @@ -34,7 +34,6 @@ class Server { const int _max_events = 100; std::string _password; void _reloadHandler(Client &client) const; - void _addOwnSocket(int sockfd); public: Server(std::string port = "6667", std::string passwd = ""); virtual ~Server(); diff --git a/src/Server.cpp b/src/Server.cpp index 90e7cc7..54469a9 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -31,8 +31,12 @@ _password(passwd) throw std::runtime_error("Server::Server: ERROR - Failed listen on port " + port); } + struct epoll_event ev{}; + ev.data.fd = _sock; + ev.events = EPOLLIN; + epoll_ctl(this->_fd, EPOLL_CTL_ADD, _sock, &ev); + _events.reserve(_max_events * sizeof(epoll_event)); - _addOwnSocket(_sock); } Server::~Server() { @@ -119,7 +123,10 @@ void Server::poll(int tout) { for (int idx = 0; idx < nbrEvents; idx++) { uint32_t event = _events[idx].events; int fd = _events[idx].data.fd; - + if (fd == _sock) { + Handler::acceptClient(_sock); + continue; + } for (uint32_t type : eventTypes) { if (_clients.count(fd) == 0) return ; @@ -150,11 +157,6 @@ void Server::registerHandler(const int fd, uint32_t eventType, std::function