本文整理汇总了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;
}