Exemplo n.º 1
0
//-------------------------------------------------------------------------------------
void Channel::clearState( bool warnOnDiscard /*=false*/ )
{
	// 清空未处理的接受包缓存
	for(uint8 i=0; i<2; i++)
	{
		if (bufferedReceives_[i].size() > 0)
		{
			BufferedReceives::iterator iter = bufferedReceives_[i].begin();
			int hasDiscard = 0;
			
			for(; iter != bufferedReceives_[i].end(); iter++)
			{
				Packet* pPacket = (*iter);
				if(pPacket->opsize() > 0)
					hasDiscard++;

				if(pPacket->isTCPPacket())
					TCPPacket::ObjPool().reclaimObject(static_cast<TCPPacket*>(pPacket));
				else
					UDPPacket::ObjPool().reclaimObject(static_cast<UDPPacket*>(pPacket));
			}

			if (hasDiscard > 0 && warnOnDiscard)
			{
				WARNING_MSG(fmt::format("Channel::clearState( {} ): "
					"Discarding {} buffered packet(s)\n",
					this->c_str(), hasDiscard));
			}

			bufferedReceives_[i].clear();
		}
	}

	clearBundle();

	lastReceivedTime_ = timestamp();

	isCondemn_ = false;
	numPacketsSent_ = 0;
	numPacketsReceived_ = 0;
	numBytesSent_ = 0;
	numBytesReceived_ = 0;
	lastTickBytesReceived_ = 0;
	proxyID_ = 0;
	strextra_ = "";
	channelType_ = CHANNEL_NORMAL;
	bufferedReceivesIdx_ = 0;

	SAFE_RELEASE(pPacketReader_);
	pFilter_ = NULL;

	stopInactivityDetection();
	this->endpoint(NULL);
}
Exemplo n.º 2
0
void Channel::startInactivityDetection(float period, float checkPeriod)
{
	stopInactivityDetection();

	// 如果周期为负数则不检查
	if(period > 0.001f)
	{
		checkPeriod = max(1.f, checkPeriod);
		mInactivityExceptionPeriod = uint64(period * stampsPerSecond() ) - uint64( 0.05f * stampsPerSecond());
		mLastReceivedTime = timestamp();

		mInactivityTimerHandle = mpNetworkManager->dispatcher().addTimer(int( checkPeriod * 1000000 ), this, (void *)Timeout_InactivityCheck);
	}
}
Exemplo n.º 3
0
//-------------------------------------------------------------------------------------
void Channel::startInactivityDetection( float period, float checkPeriod )
{
	stopInactivityDetection();

	// 如果周期为负数则不检查
	if(period > 0.f)
	{
		inactivityExceptionPeriod_ = uint64( period * stampsPerSecond() );
		lastReceivedTime_ = timestamp();

		inactivityTimerHandle_ =
			this->dispatcher().addTimer( int( checkPeriod * 1000000 ),
										this, (void *)TIMEOUT_INACTIVITY_CHECK );
	}
}
Exemplo n.º 4
0
//-------------------------------------------------------------------------------------
void Channel::destroy()
{
	if(isDestroyed_)
	{
		CRITICAL_MSG("is channel has Destroyed!");
		return;
	}

	if(pNetworkInterface_ != NULL && pEndPoint_ != NULL)
	{
		pNetworkInterface_->onChannelGone(this);

		if(protocoltype_ == PROTOCOL_TCP)
		{
			pNetworkInterface_->dispatcher().deregisterFileDescriptor(*pEndPoint_);
			pEndPoint_->close();
		}
	}

	stopInactivityDetection();
	isDestroyed_ = true;
	this->decRef();
}
Exemplo n.º 5
0
void Channel::clearState(bool warnOnDiscard)
{
	if (mBufferedReceives.size() > 0)
	{
		BufferedReceives::iterator iter = mBufferedReceives.begin();
		int hasDiscard = 0;

		for(; iter != mBufferedReceives.end(); ++iter)
		{
			Packet* pPacket = (*iter);
			if(pPacket->length() > 0)
				hasDiscard++;

			reclaimPacket(pPacket->isTCPPacket(), pPacket);
		}

		if (hasDiscard > 0 && warnOnDiscard)
		{
			// 			WARNING_MSG(fmt::format("Channel::clearState( {} ): "
			// 				"Discarding {} buffered packet(s)\n",
			// 				this->c_str(), hasDiscard));
		}

		mBufferedReceives.clear();
	}

	clearBundle();

	mLastReceivedTime = timestamp();

	mNumPacketsSent = 0;
	mNumPacketsReceived = 0;
	mNumBytesSent = 0;
	mNumBytesReceived = 0;
	mLastTickBytesReceived = 0;
	proxyID_ = 0;
	mStrExtra = "";
	mChannelType = Chanel_Normal;

	if(mpEndPoint && mProtocolType == Protocol_TCP && !this->isDestroyed())
	{
		this->stopSend();

		if(mpNetworkManager)
		{
			if(!this->isDestroyed())
				mpNetworkManager->dispatcher().deregisterReadFileDescriptor(*mpEndPoint);
		}
	}

	mFlags = 0;
	mpFilter = NULL;

	stopInactivityDetection();

	if(mpEndPoint)
	{
		mpEndPoint->close();
		this->pEndPoint(NULL);
	}
}