1. 说明
- 一个EPollPoller类,需要了解关于epoll的相关知识,主要是三个函数
- epoll_create1
- epoll_wait
- epoll_ctl
2. 变量
-
类型定义
- EventList,epoll_event结构的列表
-
epollfd_
- 用epoll_create1()返回的epollfd,构造函数中就生成了
-
events_
- EventList类型
-
channels_
- 继承过来的,map<int,Channel*>类型
-
static const int kInitEventListSize = 16;
- 如名,存储响应事件列表的大小,即同时处理的最大事件数
3. 函数
1. 私有
-
void fillActiveChannels(int numEvents,
ChannelList* activeChannels) const;- 遍历events_列表,这个列表就是相应事件列表,实际上就是关注的Channel,把这些Channel加入到参数activeChannels中
-
void update(int operation, Channel* channel);
- 调用epoll_ctl()函数,根据参数的操作进行处理,更新epoll关注事件
-
static const char* operationToString(int op);
- 把操作方式变为字符串返回
2. 公有(除了构造都是重载)
-
构造
- 初始化变量
-
析构
- close(epollfd_)
-
Timestamp poll(int timeoutMs, ChannelList* activeChannels)
- 通过epoll_wait()调用(返回活跃fd的数量),调用私有函数fillActiveChannels()把活跃的通道加入到参数activeChannels中
-
void updateChannel(Channel* channel) override;
- 如果这个channel不在epoll队列中就加入.在的话就更新一下,都调用的私有函数update()
-
void removeChannel(Channel* channel) override;
- 通过一系列操作把这个channel删除了,从关注的channel中删除,从epoll中删除这个关注事件