handy源码阅读(五):PollerBase类

使用poll内核函数等待事件发生:

struct PollerBase: private noncopyable {
  int64_t id_;
  int lastActive_;
  PollerBase(): lastActive_(-1) {
    static std::atomic id(0);
    id_ = ++id;
  }

  virtual void addChannel(Channel* ch) = 0;
  virtual void removeChannel(Channel* ch) = 0;
  virtual void updateChannel(Channel* ch) = 0;
  virtual ~PollerBase() {};
};

struct PollerEpoll : public PollerBase {
int fd_;
std::set liveChannels_;
struct epoll_event activeEvs_[kMaxEvents];

PollerEpoll();
~PollerEpoll();
void addChannel(Channel* ch) override;
void removeChannel(Channel* ch) override;
void updateChannel(Channel* ch) override;
void loop_once(int waitMs) override;
};

 

你可能感兴趣的:(handy源码阅读(五):PollerBase类)