peakzhang 发表于 2007-12-13 23:40:48

学习Reacto的r疑问

如果用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);

不知道我的表述有没有问题

peakzhang 发表于 2007-12-13 23:40:56

register_handler
      (this, ACE_Event_Handler::WRITE_MASK);

你去看看源码就知道,它在内部有调用处理器(this)的get_handle方法来获取handle

peakzhang 发表于 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 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().
页: [1]
查看完整版本: 学习Reacto的r疑问