-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoll.cpp
More file actions
37 lines (33 loc) · 776 Bytes
/
poll.cpp
File metadata and controls
37 lines (33 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "Server.hpp"
void Server::setupPoll(int fd)
{
memset(_userPoll, 0, sizeof(_userPoll));
_activePoll = 1;
_userPoll[0].fd = fd;
_userPoll[0].events = POLLIN;
}
int Server::addConnection(int clientSocket)
{
if (_activePoll >= SOMAXCONN)
std::cerr << "ADD TO POLL FAILURE" << std::endl;
_userPoll[_activePoll].fd = clientSocket;
_userPoll[_activePoll].events = POLLIN;
_activePoll++;
return (0);
}
int Server::removeConnection(int clientFD)
{
int i = -1;
for (int j = 0; j < _activePoll; j++)
{
if (_userPoll[j].fd == clientFD)
i = j;
}
if (i == -1)
std::cerr << "NO POLL FOUND" << std::endl;
_userPoll[i].fd = _userPoll[_activePoll - 1].fd;
_userPoll[i].events = POLLIN;
_userPoll[_activePoll - 1].fd = -1;
_activePoll--;
return (0);
}