-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEpollPoller.h
44 lines (33 loc) · 1.01 KB
/
EpollPoller.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
#pragma once
#include <vector>
#include <sys/epoll.h>
#include "Poller.h"
#include "EventLoop.h"
#include "Timestamp.h"
// 只使用了指针类型,故只使用前置声明
class Channel;
/**
* @brief epoll的使用的
* epoll_create
* epoll_ctl add/mod/del
* epoll_wait
*
*/
class EpollPoller : public Poller {
public:
EpollPoller(EventLoop *loop);
~EpollPoller() override; // 可执行编译器检查虚函数
// 重写抽象基类IO复用的接口
Timestamp poll(int timeoutMS, ChannelList *activeChannel) override;
void updateChannel(Channel *channel) override;
void removeChannel(Channel *channel) override;
private:
static const int kInitEventListSize = 16;
// 填写活跃的链接
void fillActiveChannels(int numEvents, ChannelList *activeChannels) const;
// 更新Channel通道(epoll_ctl的调用)
void update(int operation, Channel *channel);
using EventList = std::vector<epoll_event>;
int epollfd_;
EventList events_; // 发生的事件
};