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


C++ Acceptor::GetFd方法代码示例

本文整理汇总了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;
}
开发者ID:chenbk85,项目名称:CuteTestForCoastTest,代码行数:78,代码来源:LeaderFollowerPool.cpp


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