summaryrefslogtreecommitdiff
path: root/tvapi/libtv/tvutils/zepoll.cpp (plain)
blob: 56f65534d2c449c2ffb70e4fccf97cd1f2a7788c
1#include "zepoll.h"
2
3
4Epoll::Epoll(int _max, int maxevents): max(_max),
5 epoll_fd(-1),
6 epoll_timeout(-1),
7 epoll_maxevents(maxevents),
8 backEvents(0)
9{
10
11}
12
13Epoll::~Epoll()
14{
15 if (isValid()) {
16 close(epoll_fd);
17 }
18 delete[] backEvents;
19}
20
21
22inline
23bool Epoll::isValid() const
24{
25 return epoll_fd > 0;
26}
27
28void Epoll::setTimeout(int timeout)
29{
30 epoll_timeout = timeout;
31}
32
33inline
34void Epoll::setMaxEvents(int maxevents)
35{
36 epoll_maxevents = maxevents;
37}
38
39inline
40const epoll_event *Epoll::events() const
41{
42 return backEvents;
43}
44
45
46
47int Epoll::create()
48{
49 epoll_fd = ::epoll_create(max);
50 if (isValid()) {
51 backEvents = new epoll_event[epoll_maxevents];
52 }
53 return epoll_fd;
54}
55
56int Epoll::add(int fd, epoll_event *event)
57{
58 if (isValid()) {
59 return ::epoll_ctl(epoll_fd, ADD, fd, event);
60 }
61 return -1;
62
63}
64
65int Epoll::mod(int fd, epoll_event *event)
66{
67 if (isValid()) {
68 return ::epoll_ctl(epoll_fd, MOD, fd, event);
69 }
70 return -1;
71
72}
73
74int Epoll::del(int fd, epoll_event *event)
75{
76 if (isValid()) {
77 return ::epoll_ctl(epoll_fd, DEL, fd, event);
78 }
79 return -1;
80}
81
82int Epoll::wait()
83{
84 if (isValid()) {
85 return ::epoll_wait(epoll_fd, backEvents, epoll_maxevents, epoll_timeout);
86 }
87 return -1;
88}
89