Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion inc/Server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 9 additions & 7 deletions src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 ;
Expand Down Expand Up @@ -150,11 +157,6 @@ void Server::registerHandler(const int fd, uint32_t eventType, std::function<voi
_reloadHandler(cli);
}

void Server::_addOwnSocket(int sockfd) {
_clients.try_emplace(sockfd, sockfd);
registerHandler(_sock, EPOLLIN, [](int socket) { Handler::acceptClient(socket); });
}

std::string Server::getTime(void) const {
string ret = ctime(&_startTime);
ret.pop_back();
Expand Down