-
Notifications
You must be signed in to change notification settings - Fork 5
/
PollEpoll.h
executable file
·49 lines (39 loc) · 1.06 KB
/
PollEpoll.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
#ifndef KHAKI_POLL_H
#define KHAKI_POLL_H
#include "EventLoop.h"
#include "Util.h"
#include <iostream>
#include <sys/epoll.h>
#include <poll.h>
#include <functional>
#include <set>
#include <unistd.h>
namespace khaki{
const int kMaxEvents = 1024;
const int kReadEv = POLLIN;
const int kWriteEv = POLLOUT;
class Channel;
class PollBase : private noncopyable {
public:
PollBase(){}
virtual ~PollBase(){}
virtual void addChannel( Channel* ch ) = 0;
virtual void updateChannel( Channel* ch ) = 0;
virtual void removeChannel( Channel* ch ) = 0;
};
class PollEpoll : public PollBase {
public:
typedef std::set<Channel*> ChannelSet;
PollEpoll();
~PollEpoll();
void poll(int timeout=500);
void addChannel( Channel* ch ) ;
void updateChannel( Channel* ch ) ;
void removeChannel( Channel* ch ) ;
private:
int evId_;
ChannelSet sChannel_;
std::vector<struct epoll_event> activeEv_;
};
}
#endif //KHAKI_POLL_H