找回密码
 用户注册

QQ登录

只需一步,快速开始

查看: 3685|回复: 2

学习Reacto的r疑问

[复制链接]
发表于 2007-12-13 23:40:48 | 显示全部楼层 |阅读模式
如果用Reactor完成这样的任务:    同一台机器上    如果有多个socket在运行        比如 sock_a和sock_b  都是流式套接字
sock_a接收到数据后 调用InputHandler_a     ;sock_b被accept后 调用 inputHandler_b

( 我觉得  Reactor注册事件时  并没有指定是在哪个socket上 发生的事件啊        他只说明了发生某个事件时由哪个Event_Handler来处理)
register_handler
      (this, ACE_Event_Handler::WRITE_MASK);

不知道我的表述有没有问题
 楼主| 发表于 2007-12-13 23:40:56 | 显示全部楼层
register_handler
      (this, ACE_Event_Handler::WRITE_MASK);

你去看看源码就知道,它在内部有调用处理器(this)的get_handle方法来获取handle
 楼主| 发表于 2007-12-13 23:41:04 | 显示全部楼层
恩  找到了

顺便贴出来

The ACE_Reactor's registration and removal methods offer multiple overloaded signatures to

facilitate their use in many different situations. For example, the register_handler()

methods can be used with any of the following signatures:

(ACE_Event_Handler *, ACE_Reactor_Mask)? In this version, the first parameter identifies

the application's event handler and the second indicates the type of event(s) the handler

is prepared to process. The method's implementation uses double-dispatching [GoF] to

obtain a handle via the handler's get_handle() method. The advantage of this design is

that application code need not obtain nor expose an I/O handle explicitly, which prevents

accidental association of the wrong handle with an event handler. Most examples in this

book therefore use this variant of register_handler().

(ACE_HANDLE, ACE_Event_Handler *, ACE_Reactor_Mask)? In this version, a new first

parameter is added to explicitly specify the I/O handle associated with the application's

event handler. This design is potentially more error-prone than the two-parameter version

above since callers can accidentally pass an I/O handle that doesn't match the event

handler. However, it allows an application to register multiple I/O handles for the same

event handler, which is necessary for handlers that must be associated with multiple IPC

objects. This method can also be used to conserve memory if a single event handler can

process events from many unrelated I/O streams that don't require maintenance of per-

handle state. The client logging daemon example in the Example portion of Section 6.2

illustrates the three parameter variant of register_handler().
您需要登录后才可以回帖 登录 | 用户注册

本版积分规则

Archiver|手机版|小黑屋|ACE Developer ( 京ICP备06055248号 )

GMT+8, 2024-11-23 15:48 , Processed in 0.014672 second(s), 5 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表