-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEpoll.h
55 lines (44 loc) · 1.06 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
//
// Created by zhikewang(王志科) on 2019-10-09.
//
#ifndef EPOLL_ECHO_EPOLL_H
#define EPOLL_ECHO_EPOLL_H
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/epoll.h>
#include <unistd.h>
#include <errno.h>
#include "common.h"
class Epoll {
public:
Epoll(): _maxevents(-1), _epfd(-1), _events(nullptr) {
}
virtual ~Epoll() {
if (_events != nullptr)
{
delete _events;
}
if (_epfd != -1)
{
close(_epfd);
}
}
int create_epool(const int max_fd);
int add_event(const int fd, const int state);
int modify_event(const int fd, const int state);
int del_event(const int fd, const int state);
int wait(const int timeout_ms=5000);
struct epoll_event& get(int i) {
if (i > _maxevents) {
LOG_PRINT("i: %d exceeds the maxevents: %d", i, _maxevents);
exit(EXIT_FAILURE);
}
return _events[i];
}
private:
int _maxevents;
int _epfd;
struct epoll_event *_events;
};
#endif //EPOLL_ECHO_EPOLL_H