forked from sorokin/echo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkqueue.hpp
81 lines (59 loc) · 1.83 KB
/
kqueue.hpp
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
79
80
81
#ifndef kqueue_hpp
#define kqueue_hpp
#include "file_descriptor.h"
#include "timer.h"
#include <functional>
#include <cstdint>
#include <sys/event.h>
#include <list>
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, int16_t event, epoll_registration*);
void modify(int fd, int16_t event, epoll_registration*);
void remove(int fd, int16_t event);
int run_timers_calculate_timeout();
private:
file_descriptor fd_;
timer timer_;
std::list<std::pair<int, int16_t>> deleted_events;
friend struct epoll_registration;
};
struct epoll_registration
{
typedef std::function<void (struct kevent)> callback_t;
epoll_registration();
epoll_registration(epoll&, int fd, std::list<int16_t> events, callback_t callback);
epoll_registration(epoll_registration const&) = delete;
epoll_registration(epoll_registration&&);
~epoll_registration();
epoll_registration& operator=(epoll_registration);
void modify(std::list<int16_t> new_events);
void swap(epoll_registration& other);
void clear();
epoll& get_epoll() const;
private:
void update();
private:
epoll* ep;
int fd;
std::list<int16_t> events;
callback_t callback;
friend struct epoll;
};
}
using sysapi::epoll;
using sysapi::epoll_registration;
#endif