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


C++ EndPoint::addr方法代码示例

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


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

示例1: processRecv

bool UDPPacketReceiver::processRecv(bool expectingPacket)
{
	Address srcAddr;
	UDPPacket* pChannelReceiveWindow = CREATE_POOL_OBJECT(UDPPacket);
	int len = pChannelReceiveWindow->recvFromEndPoint(*m_pEndPoint, &srcAddr);

	if(len <= 0)
	{
		RELEASE_POOL_OBJECT(UDPPacket, pChannelReceiveWindow);
		PacketReceiver::RecvState rstate = this->checkSocketErrors(len, expectingPacket);
		return rstate == PacketReceiver::RECV_STATE_CONTINUE;
	}

	Channel* pSrcChannel = m_pNetworkInterface->findChannel(srcAddr);
	if(pSrcChannel == NULL)
	{
		EndPoint* pNewEndPoint = CREATE_POOL_OBJECT(EndPoint);

		pNewEndPoint->addr(srcAddr.m_port, srcAddr.m_ip);

		pSrcChannel = CREATE_POOL_OBJECT(Channel, m_pNetworkInterface, pNewEndPoint, nullptr, PROTOCOL_UDP);
		if (!pSrcChannel)
		{
			pSrcChannel->destroy();
			RELEASE_POOL_OBJECT(Channel, pSrcChannel);
			RELEASE_POOL_OBJECT(UDPPacket, pChannelReceiveWindow);
			return false;
		}

		if(!m_pNetworkInterface->registerChannel(pSrcChannel))
		{
			RELEASE_POOL_OBJECT(UDPPacket, pChannelReceiveWindow);
			pSrcChannel->destroy();
			RELEASE_POOL_OBJECT(Channel, pSrcChannel);
			return false;
		}
	}
	SLASSERT(pSrcChannel != NULL, "wtf");

	if(pSrcChannel->isCondemn())
	{
		RELEASE_POOL_OBJECT(UDPPacket, pChannelReceiveWindow);
		m_pNetworkInterface->deregisterChannel(pSrcChannel);
		pSrcChannel->destroy();
		RELEASE_POOL_OBJECT(Channel, pSrcChannel);
		return false;
	}

	Reason ret = this->processPacket(pSrcChannel, pChannelReceiveWindow);

	if(ret != REASON_SUCCESS)
	{

	}

	return true;
}
开发者ID:DuanDechao,项目名称:shyloo,代码行数:57,代码来源:sludp_packet_receiver.cpp

示例2: processRecv

//-------------------------------------------------------------------------------------
bool UDPPacketReceiver::processRecv(bool expectingPacket)
{	
	Address	srcAddr;
	UDPPacket* pChannelReceiveWindow = UDPPacket::ObjPool().createObject();
	int len = pChannelReceiveWindow->recvFromEndPoint(*pEndpoint_, &srcAddr);

	if (len <= 0)
	{
		UDPPacket::ObjPool().reclaimObject(pChannelReceiveWindow);
		PacketReceiver::RecvState rstate = this->checkSocketErrors(len, expectingPacket);
		return rstate == PacketReceiver::RECV_STATE_CONTINUE;
	}
	
	Channel* pSrcChannel = pNetworkInterface_->findChannel(srcAddr);

	if(pSrcChannel == NULL) 
	{
		EndPoint* pNewEndPoint = EndPoint::ObjPool().createObject();
		pNewEndPoint->addr(srcAddr.port, srcAddr.ip);

		pSrcChannel = Network::Channel::ObjPool().createObject();
		bool ret = pSrcChannel->initialize(*pNetworkInterface_, pNewEndPoint, Channel::EXTERNAL, PROTOCOL_UDP);
		if(!ret)
		{
			ERROR_MSG(fmt::format("UDPPacketReceiver::processRecv: initialize({}) is failed!\n",
				pSrcChannel->c_str()));

			pSrcChannel->destroy();
			Network::Channel::ObjPool().reclaimObject(pSrcChannel);
			UDPPacket::ObjPool().reclaimObject(pChannelReceiveWindow);
			return false;
		}

		if(!pNetworkInterface_->registerChannel(pSrcChannel))
		{
			ERROR_MSG(fmt::format("UDPPacketReceiver::processRecv: registerChannel({}) is failed!\n",
				pSrcChannel->c_str()));

			UDPPacket::ObjPool().reclaimObject(pChannelReceiveWindow);
			pSrcChannel->destroy();
			Network::Channel::ObjPool().reclaimObject(pSrcChannel);
			return false;
		}
	}
	
	KBE_ASSERT(pSrcChannel != NULL);

	if(pSrcChannel->isCondemn())
	{
		UDPPacket::ObjPool().reclaimObject(pChannelReceiveWindow);
		pNetworkInterface_->deregisterChannel(pSrcChannel);
		pSrcChannel->destroy();
		Network::Channel::ObjPool().reclaimObject(pSrcChannel);
		return false;
	}

	Reason ret = this->processPacket(pSrcChannel, pChannelReceiveWindow);

	if(ret != REASON_SUCCESS)
		this->dispatcher().errorReporter().reportException(ret, pEndpoint_->addr());
	
	return true;
}
开发者ID:Eayon,项目名称:kbengine,代码行数:64,代码来源:udp_packet_receiver.cpp


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