??? 多路分配的入口函數handle_events,在框架的實現接口類中定義
??? 多路分配的主體實現函數event_handling,在ACE_WFMO_Reactor中定義,偽
實現代碼如下
int ACE_WFMO_Reactor::event_handling (ACE_Time_Value *max_wait_time,
????????????????????????????????????? int alertable)
{
? int result = 0;
?
? do
? {
????? //等待在句柄集上發生的事件
????? //wait_for_multiple_events的具體實現是使用
????? //WaitForMultipleObjectsEx函數
????? DWORD wait_status = this->wait_for_multiple_events (timeout,
????????????????????????????????????????????????????????? alertable);
????? //分發事件
????? result = this->safe_dispatch (wait_status);
? }while (result == 0);
? return result;
}
??? 分發的主體函數是dispatch_handles,在ACE_WFMO_Reactor中定義,偽實現
代碼如下
int ACE_WFMO_Reactor::dispatch_handles (DWORD wait_status)
{
? DWORD dispatch_slot = 0;
? //活動的句柄總數
? DWORD max_handlep1 = this->handler_rep_.max_handlep1 ();
? //查找要分發的句柄的索引
? for (int number_of_handlers_dispatched = 1;;++number_of_handlers_dispatched)
? {
????? //計算有事件發生,要分發的句柄索引
????? dispatch_slot += wait_status - WAIT_OBJECT_0;
????? //分發給相應的事件處理對象
????? if (this->dispatch_handler (dispatch_slot, max_handlep1) == -1)
??????? return -1;
????? ++dispatch_slot;
????? if (dispatch_slot >= max_handlep1)
??????? return number_of_handlers_dispatched;//分發了幾個事件
????? //檢查剩下的句柄中有沒有有事件發生的
????? wait_status = this->poll_remaining_handles (dispatch_slot);
????? switch (wait_status)
????? {
??????? case WAIT_FAILED: // Failure.
????????? ACE_OS::set_errno_to_last_error ();
????????? /* FALLTHRU */
??????? case WAIT_TIMEOUT:
????????? // There are no more handles ready, we can return.
????????? return number_of_handlers_dispatched;//分發了幾個事件
????? }
? }
}
??? 找到具體事件處理對象主體函數complex_dispatch_hander,在ACE_WFMO_Reactor
中定義,為代碼如下
int ACE_WFMO_Reactor::complex_dispatch_handler (DWORD slot,
??????????????????????????????????????????????? ACE_HANDLE event_handle)
{
? //找到當前的分發的信息
? ACE_WFMO_Reactor_Handler_Repository::Current_Info ¤t_info =
??? this->handler_rep_.current_info ()[slot];
? WSANETWORKEVENTS events;
? ACE_Reactor_Mask problems = ACE_Event_Handler::NULL_MASK;
? if (::WSAEnumNetworkEvents ((SOCKET) current_info.io_handle_,
????????????????????????????? event_handle,
????????????????????????????? &events) == SOCKET_ERROR)
??? problems = ACE_Event_Handler::ALL_EVENTS_MASK;
? else
? {
????? //發生的事件于要檢測的事件是否相同,相同就分發
????? events.lNetworkEvents &= current_info.network_events_;
????? while (events.lNetworkEvents != 0)
????? {
????????? ACE_Event_Handler *event_handler = current_info.event_handler_;
????????? //調用事件處理對象,進行事件處理
????????? problems |= this->upcall (current_info.event_handler_,
??????????????????????????????????? current_info.io_handle_,
??????????????????????????????????? events);
????????? if (this->handler_rep_.scheduled_for_deletion (slot))
??????????? break;
????? }
? }
? return 0;
}
posted on 2007-02-22 11:46
walkspeed 閱讀(1397)
評論(0) 編輯 收藏 引用 所屬分類:
ACE Farmeworks