-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoller.h
More file actions
40 lines (31 loc) · 1.02 KB
/
Poller.h
File metadata and controls
40 lines (31 loc) · 1.02 KB
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
#pragma once
#include "noncopyable.h"
#include "Timestamp.h"
#include <vector>
#include <unordered_map>
class EventLoop;
class Channel;
/**
* IO复用封装类,封装POLL,EPOLL功能函数,统一对外接口
*/
class Poller : noncopyable {
public:
using ChannelList = std::vector<Channel*>;
Poller(EventLoop* loop);
virtual ~Poller() = default;
// poller统一接口,包括操作,更新,删除,由继承实现
virtual Timestamp poll (int timeoutMs, ChannelList *activeChannels) = 0;
virtual void updateChannel(Channel* channel) = 0;
virtual void removeChannel(Channel* channel) = 0;
// 判断通道是否在该IO复用中
bool hasChannel(Channel* channel) const;
// 获取loop默认IO复用具体实现
static Poller* newDefaultPoller(EventLoop* loop);
protected:
// fd, channle实例
using ChannelMap = std::unordered_map<int, Channel*>;
// poller监视的所有channels
ChannelMap channels_;
private:
EventLoop* ownerloop_; // 所属的事件训练loop
};