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


C++ Bundle::pCurrPacket方法代码示例

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


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

示例1: checkComponentUsable

//-------------------------------------------------------------------------------------		
bool Components::checkComponentUsable(const Components::ComponentInfos* info)
{
	Mercury::EndPoint epListen;
	epListen.socket(SOCK_STREAM);
	if (!epListen.good())
	{
		ERROR_MSG("Components::checkComponentUsable: couldn't create a socket\n");
		return true;
	}
	
	int trycount = 0;

	while(true)
	{
		if(epListen.connect(info->pIntAddr->port, info->pIntAddr->ip) == -1)
		{
			KBEngine::sleep(30);
			trycount++;
			if(trycount > 3)
			{
				ERROR_MSG("Components::checkComponentUsable: couldn't connect to:%s\n", info->pIntAddr->c_str());
				return false;
			}
		}
		
		break;
	}
	
	Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject();
	COMMON_MERCURY_MESSAGE(info->componentType, (*pBundle), lookApp);
	epListen.send(pBundle->pCurrPacket()->data(), pBundle->pCurrPacket()->wpos());
	Mercury::Bundle::ObjPool().reclaimObject(pBundle);

	epListen.setnodelay(true);
	epListen.setnonblocking(true);

	fd_set	fds;
	struct timeval tv = { 0, 100000 }; // 100ms

	FD_ZERO( &fds );
	FD_SET((int)epListen, &fds);

	int selgot = select(epListen+1, &fds, NULL, NULL, &tv);
	if(selgot == 0)
	{
		return true;	// 超时可能对方繁忙
	}
	else if(selgot == -1)
	{
		return true;
	}
	else
	{
		COMPONENT_TYPE ctype;
		COMPONENT_ID cid;

		Mercury::TCPPacket packet;
		packet.resize(255);
		int recvsize = sizeof(ctype) + sizeof(cid);
		int len = epListen.recv(packet.data(), recvsize);
		packet.wpos(len);
		
		if(recvsize != len)
		{
			ERROR_MSG("Components::checkComponentUsable: packet invalid.\n");
			return true;
		}

		packet >> ctype >> cid;

		if(ctype != info->componentType || cid != info->cid)
		{
			ERROR_MSG("Components::checkComponentUsable: invalid component.\n");
			return false;
		}
	}

	return true;
}
开发者ID:ChowZenki,项目名称:kbengine,代码行数:80,代码来源:components.cpp

示例2: checkComponentUsable

//-------------------------------------------------------------------------------------		
bool Components::checkComponentUsable(const Components::ComponentInfos* info)
{
	// 不对其他machine做处理
	if(info->componentType == MACHINE_TYPE)
	{
		return true;
	}

	bool islocal = _pNetworkInterface->intaddr().ip == info->pIntAddr->ip ||
			_pNetworkInterface->extaddr().ip == info->pIntAddr->ip;

	// 如果是本机应用则判断是否还在运行中
	if(islocal && info->pid > 0)
	{
		SystemInfo::PROCESS_INFOS sysinfos = SystemInfo::getSingleton().getProcessInfo(info->pid);
		if(sysinfos.error)
		{
			WARNING_MSG(boost::format("Components::checkComponentUsable: not found pid(%1%)\n") % info->pid);
			//return false;
		}
		else
		{
			Components::ComponentInfos* winfo = findComponent(info->cid);
			if(winfo)
			{
				winfo->cpu = sysinfos.cpu;
				winfo->usedmem = (uint32)sysinfos.memused;

				winfo->mem = float((winfo->usedmem * 1.0 / SystemInfo::getSingleton().totalmem()) * 100.0);
			}
		}
	}

	Mercury::EndPoint epListen;
	epListen.socket(SOCK_STREAM);
	if (!epListen.good())
	{
		ERROR_MSG("Components::checkComponentUsable: couldn't create a socket\n");
		return true;
	}
	
	epListen.setnonblocking(true);

	while(true)
	{
		fd_set	frds, fwds;
		struct timeval tv = { 0, 300000 }; // 100ms

		FD_ZERO( &frds );
		FD_ZERO( &fwds );
		FD_SET((int)epListen, &frds);
		FD_SET((int)epListen, &fwds);

		if(epListen.connect(info->pIntAddr->port, info->pIntAddr->ip) == -1)
		{
			int selgot = select(epListen+1, &frds, &fwds, NULL, &tv);
			if(selgot > 0)
			{
				break;
			}

			ERROR_MSG(boost::format("Components::checkComponentUsable: couldn't connect to:%1%\n") % info->pIntAddr->c_str());
			return false;
		}
	}
	
	epListen.setnodelay(true);

	Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject();

	// 由于COMMON_MERCURY_MESSAGE不包含client, 如果是bots, 我们需要单独处理
	if(info->componentType != BOTS_TYPE)
	{
		COMMON_MERCURY_MESSAGE(info->componentType, (*pBundle), lookApp);
	}
	else
	{
		(*pBundle).newMessage(BotsInterface::lookApp);
	}

	epListen.send(pBundle->pCurrPacket()->data(), pBundle->pCurrPacket()->wpos());
	Mercury::Bundle::ObjPool().reclaimObject(pBundle);

	fd_set	fds;
	struct timeval tv = { 0, 300000 }; // 100ms

	FD_ZERO( &fds );
	FD_SET((int)epListen, &fds);

	int selgot = select(epListen+1, &fds, NULL, NULL, &tv);
	if(selgot == 0)
	{
		return true;	// 超时可能对方繁忙
	}
	else if(selgot == -1)
	{
		return true;
	}
	else
//.........这里部分代码省略.........
开发者ID:Jimlan,项目名称:kbengine,代码行数:101,代码来源:components.cpp


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