blob: 9ba4c25003e83afaeacee8931f60c9f647e50209
1 | |
2 | #ifndef EPOLL_H |
3 | #define EPOLL_H |
4 | |
5 | #include <sys/epoll.h> |
6 | #include <unistd.h> |
7 | |
8 | |
9 | /** |
10 | * @brief The Epoll class 对epoll的封装 |
11 | */ |
12 | class Epoll { |
13 | public: |
14 | /** |
15 | * |
16 | */ |
17 | enum EPOLL_OP {ADD = EPOLL_CTL_ADD, MOD = EPOLL_CTL_MOD, DEL = EPOLL_CTL_DEL}; |
18 | /** |
19 | * 最大的连接数和最大的回传事件数 |
20 | */ |
21 | Epoll(int _max = 30, int maxevents = 20); |
22 | ~Epoll(); |
23 | int create(); |
24 | int add(int fd, epoll_event *event); |
25 | int mod(int fd, epoll_event *event); |
26 | int del(int fd, epoll_event *event); |
27 | void setTimeout(int timeout); |
28 | void setMaxEvents(int maxevents); |
29 | int wait(); |
30 | const epoll_event *events() const; |
31 | const epoll_event &operator[](int index) |
32 | { |
33 | return backEvents[index]; |
34 | } |
35 | private: |
36 | bool isValid() const; |
37 | int max; |
38 | int epoll_fd; |
39 | int epoll_timeout; |
40 | int epoll_maxevents; |
41 | epoll_event *backEvents; |
42 | }; |
43 | |
44 | |
45 | |
46 | |
47 | #endif //EPOLL_H |
48 | |
49 |