Channel 是单个文件描述符进行事件分发的类
https://blog.csdn.net/qq_43390943/article/details/89873302
中介绍了Channel在新连接到达时的作用。这里在源码中看一些Channel 处理了哪些东西。
头文件
//事件分发器,每个事件分发器对应一个文件描述符,监听该文件描述符上的所有的事件
class Channel : noncopyable
{
public:
//两种回调函数的形式
typedef std::function<void()> EventCallback;
typedef std::function<void(Timestamp)> ReadEventCallback;
Channel(EventLoop* loop, int fd);
~Channel();
void handleEvent(Timestamp receiveTime);
//注册回调函数
void setReadCallback(ReadEventCallback cb)
{
readCallback_ = std::move(cb); }
void setWriteCallback(EventCallback cb)
{
writeCallback_ = std::move(cb); }
void setCloseCallback(EventCallback cb)
{
closeCallback_ = std::move(cb); }
void setErrorCallback(EventCallback cb)
{
errorCallback_ = std::move(cb); }
/// Tie this channel to the owner object managed by shared_ptr,
/// prevent the owner object being destroyed in handleEvent.
void tie(const std::shared_ptr<void>&);
int fd() const {
return fd_; } //返回该channel 对应的文件描述符
int events