muduo库的学习5---loop的基本设计---Channel细节
来源:互联网 发布:淘宝图片怎么上传清晰 编辑:程序博客网 时间:2024/06/08 05:58
类似于EventLoop的分析,忽略一些次要成员。
1.类定义
class Channel{typedef boost::function<void()> EventCallback;typedef boost::function<void(Timestamp)> ReadEventCallback;/***************Function Member******************///bind with loop and fdChannel(EventLoop* loop, int fd);~Channel();//bind with callbackvoid setReadCallBack(const ReadEventCallback& cb);void setWriteCallBack(const EventCallback& cb);void setCloseCallBack(cosnt EventCallback& cb);void setErrorCallBack(const EventCallback& cb);//change channel in Pollervoid enableReading();void enableWriting();void disableReading();void disableWriting();void update();void remove();//key functionvoid handleEvent(Timerstamp receiveTime);/*************Data Member***********************///bind with loop and fdEventLoop* loop;const int fd;//bind with callbackReadEventCallback readCallback;EventCallback writeCallback;EventCallback closeCallback;EventCallback errorCallback;//change channel in Pollerconst int fd;int events;int revents;}
2.channel与libev中的watcher对比
①init <------------> Channel::setXXXCallback()
②set <------------> Channel::enablingXXX()
③start <------------> Channel::update()
④stop <------------> Channel::remove()
当然这只是功能上大体对应,并不是严格对应。
比如enablingXXX本身就包含了设定监听的具体内容(read/write)以及调用update
3.三种channel
在loop这几个文件的学习之中,目前共遇到3种channel(从处理fd上来说)
IO channel---socketfd
Timer channel---timerfd
wakeup channel---eventfd
(1)IO channel
其操作由用户来指定,各种功能操作被封装到更高层的类里面(2)Timer channel
①New
TimerQueue::TimerQueue()
②SetCallback
TimerQueue::TimerQueue()
③Enablingxxx
TimerQueue::TimerQueue()
TimerQueue::addTimer()
④HandleEvent
TimerQueue::handleRead()
TimerQueue::cancel()
TimerQueue::~TimerQueue()
(3)Wakeup channel
①New
EventLoop::EventLoop()
②SetCallback
EventLoop::EventLoop()
③Enablingxxx
EventLoop::EventLoop()
EventLoop::runInLoop()
④HandleEvent
EventLoop::doPendingFunctors()
EventLoop::RemoveChannel()
EventLoop::~EventLoop()
- muduo库的学习5---loop的基本设计---Channel细节
- muduo库的学习4---loop的基本设计---EventLoop细节
- muduo库的学习3---loop基本设计---总论
- muduo库的学习2--Socket的基本设计---代码细节
- muduo库的学习6---Buffer的基本设计
- muduo库的学习1---socket基本设计---总论
- muduo的Channel类剖析
- muduo库的学习7---TcpServer与TcpClient的基本设计---总论
- muduo库的学习8---TcpServer与TcpClient的基本设计---TcpServer
- muduo库的学习10---TcpServer与TcpClient的基本设计---TcpConnection建立与关闭
- muduo库的学习11---TcpServer与TcpClient的基本设计---TcpConnection接收与发送
- muduo库的学习9---TcpServer与TcpClient的基本设计---TcpConnection成员
- muduo网络库学习(二)对套接字和监听事件的封装Channel
- muduo网络库学习(三)定时器TimerQueue的设计
- 学习muduo(框架的设计)
- muduo网络库中buffer的设计
- muduo网络库中buffer的设计
- Channel的基本使用
- Ubuntu完美下载Android源码
- Java Effective 节选
- Python数据结构(一)关于字典
- 虚拟机随谈(一):解释器,树遍历解释器,基于栈与基于寄存器,大杂烩 http://rednaxelafx.iteye.com/blog/492667
- poj 1671 Rhyme Schemes
- muduo库的学习5---loop的基本设计---Channel细节
- 4321: queue2 思路题 DP
- 软件开发技术:开源软件(open source)
- 手机页面的切换(setContentView的应用)
- 数组指针和指针数组的区别
- leetcode之全排列(Permutation)
- [自定义组件之三]利用calyer实现进度条效果
- pch文件的使用
- Linux内核实践 - 如何添加网络协议[一]:目的