Reactor 模式 EventLoop类
2015-04-27 12:05
323 查看
non-blocking IO + IO multiplexing 即 Reactor 模式
程序的基本结构是一个事件循环(event loop),以事件驱动(event-driven)和事件回调的方式实现业务逻辑
伪代码:
while(true)
{
int timeout_ms=max(1000,getNexTimedCallback());
int retval = ::poll(fds,nfds,timeout_ms);
if(retval<0){
错误处理
}
else{
处理到期的timers,回调用户的timer handler,
if (retval > 0){
处理IO事件,回调用户的IO event handler
}
}
}
程序的基本结构是一个事件循环(event loop),以事件驱动(event-driven)和事件回调的方式实现业务逻辑
伪代码:
while(true)
{
int timeout_ms=max(1000,getNexTimedCallback());
int retval = ::poll(fds,nfds,timeout_ms);
if(retval<0){
错误处理
}
else{
处理到期的timers,回调用户的timer handler,
if (retval > 0){
处理IO事件,回调用户的IO event handler
}
}
}
相关文章推荐
- Redis与Reactor模式
- Reactor模式,或者叫反应器模式
- 两种高性能I/O设计模式(Reactor/Proactor)的比较
- reactor和proactor模式
- Reactor模式,或者叫反应器模式
- muduo源代码分析--Reactor模式在muduo中的使用
- 发布一个基于 Reactor 模式的 C++ 网络库
- Reactor 模式的简单实现
- 项目中用到的设计模式:Reactor设计模式
- muduo源码分析--Reactor模式的在muduo中的使用(二)
- reactor模式
- 发布一个基于 Reactor 模式的 C++ 网络库
- 基于Reactor模式的libevent网络库之浅析与使用
- reactor模式 C++
- Java NIO 反应器(Reactor)模式
- 对ACE反应器Reactor模式的示例程序分析
- Reactor模式(反应器模式)
- ACE反应器(Reactor)模式
- Java进阶(五)Java I/O模型从BIO到NIO和Reactor模式
- ACE - Reactor模式源码剖析及具体实现(大量源码慎入)