分类: C/C++
2010-06-25 17:06:35
///
class handler
{
public:
virtual void onRead() = 0;
virtual void onWrite() = 0;
virtual void onAccept() = 0;
}; 
class dispatch
{
public:
void poll()
{
// add fd in the set.
//
// poll every fd
int c = select( 0, &read_fd, &write_fd, 0, 0 );
if( c > 0 )
{
for each fd in the read_fd_set
{ if fd can read
_handler->onRead();
if fd can accept
_handler->onAccept();
} 
for each fd in the write_fd_set
{
if fd can write
_handler->onWrite();
}
}
} 
void setHandler( handler *_h )
{
_handler = _h;
} 
private:
handler *_handler;
}; 
/// application
class MyHandler : public handler
{
public:
void onRead()
{
} 
void onWrite()
{
} 
void onAccept()
{
}
}; 

class AsyIOProcessor
{
public:
void do_read()
{
//
send read operation to OS
// read io finished.and dispatch notification
_proactor->dispatch_read();
} 
private:
Proactor *_proactor;
}; 
class Proactor
{
public:
void dispatch_read()
{
_handlerMgr->onRead();
} 
private:
HandlerManager *_handlerMgr;
}; 
class HandlerManager
{
public:
typedef std::list
public:
void onRead()
{
// notify all the handlers.
std::for_each( _handlers.begin(), _handlers.end(), onRead );
} 
private:
HandlerList *_handlers;
}; 
class Handler
{
public:
virtual void onRead() = 0;
}; 
// application level handler.
class MyHandler : public Handler
{
public:
void onRead()
{
//
}
}; 

# re: Proactor和Reactor模式_继续并发系统设计的扫盲 2008-06-06 15:13 关中刀客
# re: Proactor和Reactor模式_继续并发系统设计的扫盲 2008-06-06 15:40 Kevin Lynx
传说哥们和我同年同月差一天就同日生(我10号:d)
还有,一直想看下你的cobra是个什么东西 回复 更多评论
# re: Proactor和Reactor模式_继续并发系统设计的扫盲 2008-06-06 16:43 关中刀客
呵呵,有缘有缘,我的cobra_win是一个网络通讯库,主要是针对iocp,采用异步多线程,底层目前已经有了自己的一套内存管理策略,比较完善的日志模快,定时器模块等等,感觉对于底层来说,已经相对的完善了,现在需要做的就是多多的改进和修正很多东西。呵呵,以后可以多多的交流~ 回复 更多评论
# re: Proactor和Reactor模式_继续并发系统设计的扫盲 2008-06-06 17:19 Kevin Lynx
难道不开源?不知道能否分享下代码。
我之前在google,baidu都搜索过你这个东西,没有发现类似googlecode之类的项目地址。。 回复 更多评论
# re: Proactor和Reactor模式_继续并发系统设计的扫盲 2008-06-11 14:15 胡章优
这两个模式在服务器开发中是应用的最多的算是
另外一点开发的重点在集群管理上面
刀客的东西可能想商业化,并没有开源的打算 回复 更多评论
# re: Proactor和Reactor模式_继续并发系统设计的扫盲[未登录] 2008-06-12 19:25
leader follower模式,是一种并发模式,也可以说是一种策略。
这些都可以在ACE的那两本网络编程的书里面看到讲解。
我最近一直看这书,一边写自己的网络库。之前写的不满意,现在重新写一个。尝试先用UML建模的方法