ACE PROACTOR EPOLL ET模式


    class CMyReactor : public ACE_Dev_Poll_Reactor  
      
    {  
      
    ....  
      
    //重载内部注册回调的接口   
      
    int register_handler_i (ACE_HANDLE handle,ACE_Event_Handler *eh,ACE_Reactor_Mask mask)  
      
    {  
      
     ACE_TRACE ("ACE_Dev_Poll_Reactor::register_handler_i");  
      
     if (handle == ACE_INVALID_HANDLE  
      || mask == ACE_Event_Handler::NULL_MASK)  
     {  
      errno = EINVAL;  
      return -1;  
     }  
      
     if (this->handler_rep_.find (handle) == 0)  
     {  
      // Handler not present in the repository.  Bind it.   
      if (this->handler_rep_.bind (handle, event_handler, mask) != 0)  
       return -1;  
      
      struct epoll_event epev;  
      ACE_OS::memset (&epev, 0, sizeof (epev));  
      static const int op = EPOLL_CTL_ADD;  
      
      epev.events  = this->reactor_mask_to_poll_event (mask);  
      epev.data.fd = handle;  
      
      if( NET_SETTING.ET_MODE )  
      {  
       epev.events |= EPOLLET;  // 关键代码,增加ET标识 [1/13/2011 yao]   
      }  
      
      if (::epoll_ctl (this->poll_fd_, op, handle, &epev) == -1)  
      {  
       ACE_ERROR ((LM_ERROR, "%p\n", "epoll_ctl"));  
       (void) this->handler_rep_.unbind (handle);  
       return -1;  
      }  
     }  
     else  
     {  
      // Handler is already present in the repository, so register it   
      // again, possibly for different event.  Add new mask to the   
      // current one.   
      if (this->mask_ops_i (handle, mask, ACE_Reactor::ADD_MASK) == -1)  
       ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "mask_ops_i"), -1);  
     }  
      
     // Note the fact that we've changed the state of the wait_set_,   
     // which is used by the dispatching loop to determine whether it can   
     // keep going or if it needs to reconsult select().   
     // this->state_changed_ = 1;   
      
     return 0;  
      
      
      
      
    }  
      
    ....  
      
    }  


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值