posts - 58,  comments - 75,  trackbacks - 0

    多路分配的入口函数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 &current_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 阅读(1374) 评论(0)  编辑 收藏 引用 所属分类: ACE Farmeworks

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理



<2007年5月>
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

常用链接

留言簿(4)

随笔分类(64)

随笔档案(58)

文章分类(3)

文章档案(3)

相册

收藏夹(9)

C++零碎

好友

搜索

  •  

积分与排名

  • 积分 - 159658
  • 排名 - 163

最新评论

阅读排行榜

评论排行榜