blob: cf4ebac276550cb57a4e1b7969fb1af08d5abbff
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 | { |
14 | public: |
15 | /** |
16 | * |
17 | */ |
18 | enum EPOLL_OP {ADD = EPOLL_CTL_ADD, MOD = EPOLL_CTL_MOD, DEL = EPOLL_CTL_DEL}; |
19 | /** |
20 | * 最大的连接数和最大的回传事件数 |
21 | */ |
22 | Epoll(int _max = 30, int maxevents = 20); |
23 | ~Epoll(); |
24 | int create(); |
25 | int add(int fd, epoll_event *event); |
26 | int mod(int fd, epoll_event *event); |
27 | int del(int fd, epoll_event *event); |
28 | void setTimeout(int timeout); |
29 | void setMaxEvents(int maxevents); |
30 | int wait(); |
31 | const epoll_event *events() const; |
32 | const epoll_event &operator[](int index) |
33 | { |
34 | return backEvents[index]; |
35 | } |
36 | private: |
37 | bool isValid() const; |
38 | int max; |
39 | int epoll_fd; |
40 | int epoll_timeout; |
41 | int epoll_maxevents; |
42 | epoll_event *backEvents; |
43 | }; |
44 | |
45 | |
46 | |
47 | |
48 | #endif //EPOLL_H |
49 | |
50 |