当前位置: 首页>>代码示例>>C++>>正文


C++ Dispatcher::OnPreEvent方法代码示例

本文整理汇总了C++中Dispatcher::OnPreEvent方法的典型用法代码示例。如果您正苦于以下问题:C++ Dispatcher::OnPreEvent方法的具体用法?C++ Dispatcher::OnPreEvent怎么用?C++ Dispatcher::OnPreEvent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Dispatcher的用法示例。


在下文中一共展示了Dispatcher::OnPreEvent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Wait


//.........这里部分代码省略.........
         else if (n == 0)
         {
             // If timeout, return success
             return true;
         }
         else
         {
             // We have signaled descriptors
             CriticalSectionScoped cr(&crit_);
             for (size_t i = 0; i < dispatchers_.size(); ++i)
             {
                 Dispatcher *pdispatcher = dispatchers_[i];
                 int fd = pdispatcher->GetDescriptor();
                 uint32 ff = 0;
                 int errcode = 0;
                 
                 // Reap any error code, which can be signaled through reads or writes.
                 // TODO: Should we set errcode if getsockopt fails?
                 if (FD_ISSET(fd, &fdsRead) || FD_ISSET(fd, &fdsWrite)) {
                     socklen_t len = sizeof(errcode);
                     ::getsockopt(fd, SOL_SOCKET, SO_ERROR, &errcode, &len);
                 }
                 
                 // Check readable descriptors. If we're waiting on an accept, signal
                 // that. Otherwise we're waiting for data, check to see if we're
                 // readable or really closed.
                 // TODO: Only peek at TCP descriptors.
                 if (FD_ISSET(fd, &fdsRead))
                 {
                     FD_CLR(fd, &fdsRead);
                     
                     if (pdispatcher->GetRequestedEvents() & DE_ACCEPT)
                     {
                         ff |= DE_ACCEPT;
                     }
                     else if (errcode || pdispatcher->IsDescriptorClosed())
                     {
                         ff |= DE_CLOSE;
                     }
                     else
                     {
                         ff |= DE_READ;
                     }
                 }
                 
                 // Check writable descriptors. If we're waiting on a connect, detect
                 // success versus failure by the reaped error code.
                 if (FD_ISSET(fd, &fdsWrite))
                 {
                     FD_CLR(fd, &fdsWrite);
                     
                     if (pdispatcher->GetRequestedEvents() & DE_CONNECT)
                     {
                         if (!errcode)
                         {
                             ff |= DE_CONNECT;
                         }
                         else
                         {
                             ff |= DE_CLOSE;
                         }
                     }
                     else
                     {
                         ff |= DE_WRITE;
                     }
                 }
                 
                 // Tell the descriptor about the event.
                 if (ff != 0)
                 {
                     pdispatcher->OnPreEvent(ff);
                     pdispatcher->OnEvent(ff, errcode);
                 }
             }
         }
         
         // Recalc the time remaining to wait. Doing it here means it doesn't get
         // calced twice the first time through the loop
         if (ptvWait)
         {
             ptvWait->tv_sec = 0;
             ptvWait->tv_usec = 0;
             struct timeval tvT;
             gettimeofday(&tvT, NULL);
             if ((tvStop.tv_sec > tvT.tv_sec) || ((tvStop.tv_sec == tvT.tv_sec)&& (tvStop.tv_usec > tvT.tv_usec)))
             {
                 ptvWait->tv_sec = tvStop.tv_sec - tvT.tv_sec;
                 ptvWait->tv_usec = tvStop.tv_usec - tvT.tv_usec;
                 if (ptvWait->tv_usec < 0)
                 {
                     ptvWait->tv_usec += 1000000;
                     ptvWait->tv_sec -= 1;
                 }
             }
         }
     }
     
     return true;
 }
开发者ID:chenjianjun571,项目名称:cioforandroid,代码行数:101,代码来源:PhysicalSocketServer.cpp


注:本文中的Dispatcher::OnPreEvent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。