-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolling.cpp
More file actions
44 lines (34 loc) · 701 Bytes
/
Polling.cpp
File metadata and controls
44 lines (34 loc) · 701 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
38
39
40
41
42
43
44
#include "Polling.h"
#include <unistd.h>
#include <assert.h>
Polling::Polling()
{
m_epollfd = epoll_create(5);
assert(m_epollfd != -1);
}
Polling::~Polling()
{
if(m_epollfd != -1)
{
close(m_epollfd);
}
}
int Polling::AddFd(int fd, int ev)
{
epoll_event event;
event.data.fd = fd;
event.events = ev;
return epoll_ctl(m_epollfd, EPOLL_CTL_ADD, fd, &event);
}
int Polling::RemoveFd(int fd)
{
epoll_event event;
return epoll_ctl(m_epollfd, EPOLL_CTL_DEL, fd, &event);
}
int Polling::ModFd(int fd, int ev)
{
epoll_event event;
event.data.fd = fd;
event.events = ev;
return epoll_ctl(m_epollfd, EPOLL_CTL_MOD, fd, &event);
}