-
Notifications
You must be signed in to change notification settings - Fork 2
/
epoll.h
78 lines (56 loc) · 1.56 KB
/
epoll.h
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef EPOLL_H
#define EPOLL_H
#include "file_descriptor.h"
#include "timer.h"
#include <functional>
#include <cstdint>
namespace sysapi
{
struct epoll;
struct epoll_registration;
struct epoll
{
typedef std::function<void ()> action_t;
epoll();
epoll(epoll const&) = delete;
epoll(epoll&&);
epoll& operator=(epoll);
void swap(epoll& other);
void run();
timer& get_timer();
private:
void add(int fd, uint32_t events, epoll_registration*);
void modify(int fd, uint32_t events, epoll_registration*);
void remove(int fd);
int run_timers_calculate_timeout();
private:
file_descriptor fd_;
timer timer_;
friend struct epoll_registration;
};
struct epoll_registration
{
typedef std::function<void (uint32_t)> callback_t;
epoll_registration();
epoll_registration(epoll&, int fd, uint32_t events, callback_t callback);
epoll_registration(epoll_registration const&) = delete;
epoll_registration(epoll_registration&&);
~epoll_registration();
epoll_registration& operator=(epoll_registration);
void modify(uint32_t new_events);
void swap(epoll_registration& other);
void clear();
epoll& get_epoll() const;
private:
void update();
private:
epoll* ep;
int fd;
uint32_t events;
callback_t callback;
friend struct epoll;
};
}
using sysapi::epoll;
using sysapi::epoll_registration;
#endif