本文整理汇总了C++中Acceptor::GetFd方法的典型用法代码示例。如果您正苦于以下问题:C++ Acceptor::GetFd方法的具体用法?C++ Acceptor::GetFd怎么用?C++ Acceptor::GetFd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Acceptor
的用法示例。
在下文中一共展示了Acceptor::GetFd方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: defined
Acceptor *HandleSet::WaitForEvents(long timeout) {
StartTrace1(HandleSet.WaitForEvents, "Timeout: " << timeout);
const long NOFDS = fDemuxTable.GetSize();
#if defined(USE_SELECT)
fd_set rfds;
FD_ZERO(&rfds);
long maxfd = 0;
#else
pollfd fds[NOFDS];
#endif
long i = 0L, sz = 0;
for (i = 0; i < NOFDS; ++i) {
#if !defined(USE_SELECT)
fds[i].events = POLLIN;
fds[i].fd = -1;
#endif
Acceptor *a = (Acceptor *) fDemuxTable[i].AsIFAObject(0);
if (a) {
int fd = a->GetFd();
if (fd >= 0) {
#if defined(USE_SELECT)
FD_SET(fd, &rfds);
if (fd > maxfd) {
maxfd = fd;
}
#else
fds[i].fd = fd;
#endif
}
}
}
if (0 == timeout) {
timeout = 200;
}
#if defined(USE_SELECT)
struct timeval tv;
tv.tv_sec = timeout / 1000;
tv.tv_usec = 1000 * (timeout % 1000);
long retCode = select(maxfd + 1, &rfds, 0, 0, &tv);
#else
long retCode = poll(fds, NOFDS, timeout);
#endif
if (0 == retCode) {
return 0; // timeout, no error
}
while (retCode < 0 && coast::system::SyscallWasInterrupted()) {
#if defined(USE_SELECT)
retCode = select(maxfd + 1, &rfds, 0, 0, &tv);
#else
retCode = poll(fds, NOFDS, timeout);
#endif
SYSERROR("select/poll call interrupted. I do a restart. Socket error number: " <<
(long) SOCKET_ERROR << " return code " << retCode << " LastSyError: " << SystemLog::LastSysError());
}
if (retCode > 0) {
for (i = 0, sz = fDemuxTable.GetSize(); i < sz; ++i) {
long idx = (fLastAcceptorUsedIndex + 1 + i) % NOFDS;
Acceptor *a = (Acceptor *) fDemuxTable[idx].AsIFAObject(0);
if (a) {
#if defined(USE_SELECT)
int fd = a->GetFd();
if (fd >= 0 && FD_ISSET(fd, &rfds))
#else
Assert(a->GetFd() == fds[idx].fd);
if (fds[idx].revents & POLLIN)
#endif
{
fLastAcceptorUsedIndex = idx;
return a;
}
}
}
}
SYSERROR("select/poll call with acceptors failed");
SYSERROR("Socket error number: " << (long) SOCKET_ERROR << " return code " << retCode <<
" LastSyError: " << SystemLog::LastSysError());
return 0;
}