本文整理汇总了C++中Dispatcher::GetDescriptor方法的典型用法代码示例。如果您正苦于以下问题:C++ Dispatcher::GetDescriptor方法的具体用法?C++ Dispatcher::GetDescriptor怎么用?C++ Dispatcher::GetDescriptor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dispatcher
的用法示例。
在下文中一共展示了Dispatcher::GetDescriptor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Wait
bool PhysicalSocketServer::Wait(int cmsWait, bool process_io)
{
// Calculate timing information
struct timeval *ptvWait = NULL;
struct timeval tvWait;
struct timeval tvStop;
if (cmsWait > 0)
{
// Calculate wait timeval
tvWait.tv_sec = cmsWait / 1000;
tvWait.tv_usec = (cmsWait % 1000) * 1000;
ptvWait = &tvWait;
// Calculate when to return in a timeval
gettimeofday(&tvStop, NULL);
tvStop.tv_sec += tvWait.tv_sec;
tvStop.tv_usec += tvWait.tv_usec;
if (tvStop.tv_usec >= 1000000) {
tvStop.tv_usec -= 1000000;
tvStop.tv_sec += 1;
}
}
// Zero all fd_sets. Don't need to do this inside the loop since
// select() zeros the descriptors not signaled
fd_set fdsRead;
FD_ZERO(&fdsRead);
fd_set fdsWrite;
FD_ZERO(&fdsWrite);
fWait_ = true;
while (fWait_)
{
int fdmax = -1;
{
CriticalSectionScoped cr(&crit_);
for (size_t i = 0; i < dispatchers_.size(); ++i)
{
// Query dispatchers for read and write wait state
Dispatcher *pdispatcher = dispatchers_[i];
if (!process_io && (pdispatcher != signal_wakeup_))
continue;
int fd = pdispatcher->GetDescriptor();
if (fd > fdmax)
fdmax = fd;
uint32 ff = pdispatcher->GetRequestedEvents();
if (ff & (DE_READ | DE_ACCEPT))
FD_SET(fd, &fdsRead);
if (ff & (DE_WRITE | DE_CONNECT))
FD_SET(fd, &fdsWrite);
}
}
// Wait then call handlers as appropriate
// < 0 means error
// 0 means timeout
// > 0 means count of descriptors ready
int n = select(fdmax + 1, &fdsRead, &fdsWrite, NULL, ptvWait);
// If error, return error.
if (n < 0)
{
if (errno != EINTR)
{
printf("select error. %d.\n", errno);
return false;
}
// Else ignore the error and keep going. If this EINTR was for one of the
// signals managed by this PhysicalSocketServer, the
// PosixSignalDeliveryDispatcher will be in the signaled state in the next
// iteration.
}
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
//.........这里部分代码省略.........