int Connections::CompleteRecv(DWORD TransferedBytes) { FUNCTION_BEGIN(); if (0 == TransferedBytes) { return 1; } IncreaseBytesRecv(TransferedBytes); if (false == _recvBuffer.IncreasePushPos(TransferedBytes)) { Logger::Log("Session[%X] Recv Buffer OverFlow : BufferCur[%d] BufferMax[%d] TransferedBytes[%u]\n", this, _recvBuffer.GetCurSize(), _recvBuffer.GetQueueSize(), TransferedBytes); return 2; } int rc = 0; WORD PacketLength = 0; Packet packet; do { rc = MakeSureCompletedPacket(&_recvBuffer, &PacketLength, _PacketEncoder); if (0 != rc) { if (2 == rc || 4 == rc) { break; } Logger::Log("Session[%X] MakeSureCompletedPacket Error[%d]\n", this, rc); return rc; } if (true != IsValidPacket(_recvBuffer.GetQueueWorkPtr(), PacketLength)) { Logger::Log("true != IsValidPacket()\n"); } packet.AttachData(_recvBuffer.GetQueueWorkPtr(), PacketLength); _recvBuffer.IncreaseWorkPos(packet.GetUsedSize()); if (_PacketEncoder) { rc = _PacketEncoder->RxDecrypt(packet); if (0 != rc) { Logger::Log("Session[%X] RxDecrypt Error[%d]\n", this, rc); return rc; } } BYTE ValidSequence = (BYTE)(_PacketRecvCount & PACKET_MAX_SEQUENCE); if (false == HasValidSequence(packet.GetPacketHeader(), ValidSequence)) { Logger::Log("Session[%X] Sequence Error[%d] PacketSEQ[%u] CurrentSEQ[%u]\n", this, rc, GetSequence(_recvBuffer.GetQueueWorkPtr()), ValidSequence); return 3; //ERR_NET_PACKET_SEQUENCE_FAIL } IncreasePacketRecv(); _NetworkRef->PostNetEventMessage((WPARAM)NETEVENT_RECV, (LPARAM)this); } while (0 == rc); rc = PostRecv(); if (0 != rc) { return rc; } return 0; }
//----------------------------------------------------------------------------------- // Purpose : // Return : //----------------------------------------------------------------------------------- // Called by Worker TH ( IOCP ) //----------------------------------------------------------------------------------- int CNtlConnection::CompleteRecv(DWORD dwTransferedBytes) { FUNCTION_BEGIN(); // Remote close if( 0 == dwTransferedBytes ) { return NTL_ERR_NET_SESSION_CLOSED; } IncreaseBytesRecv( dwTransferedBytes ); if( false == m_recvBuffer.IncreasePushPos( dwTransferedBytes ) ) //-> µ¿±âÈÇÊ¿ä { NTL_LOGDL( LOG_NETWORK, "Session[%X] Recv Buffer OverFlow : BufferCur[%d] BufferMax[%d] TransferedBytes[%u]", this, m_recvBuffer.GetCurSize(), m_recvBuffer.GetQueueSize(), dwTransferedBytes ); return NTL_ERR_NET_SESSION_RECV_BUFFER_OVERFLOW; } int rc = NTL_SUCCESS; WORD wPacketLength = 0; #if 0 while( MakeSureCompletedPacket( &m_recvBuffer, &wPacketLength, m_pPacketEncoder ) ) { if( true != IsValidPacket( m_recvBuffer.GetQueueWorkPtr(), wPacketLength ) ) { NTL_LOG_ASSERT("true != IsValidPacket()"); } CNtlPacket packet; packet.Attach( m_recvBuffer.GetQueueWorkPtr(), wPacketLength ); m_recvBuffer.IncreaseWorkPos( packet.GetUsedSize() ); if( m_pPacketEncoder ) { rc = m_pPacketEncoder->RxDecrypt( packet ); if( NTL_SUCCESS != rc ) { return rc; } } // [9/10/2007 zeroera] : ¼³¸í : sequence°ªÀº 0 ~ 255 BYTE byValidSequence = (BYTE) ( m_dwPacketRecvCount & PACKET_MAX_SEQUENCE ); if( false == HasValidSequence( packet.GetPacketHeader(), byValidSequence ) ) { return NTL_ERR_NET_PACKET_SEQUENCE_FAIL; } IncreasePacketRecv(); //NTL_PRINT(PRINT_SYSTEM, "Session[%X]\tCompleteRecv Complete recvBufferSize[%d], TotalRecvBytes[%u]", this, m_recvBuffer.GetCurSize(), m_dwTotalRecvSize ); m_pNetworkRef->PostNetEventMessage( (WPARAM)NETEVENT_RECV, (LPARAM)this ); } #else CNtlPacket packet; do { rc = MakeSureCompletedPacket( &m_recvBuffer, &wPacketLength, m_pPacketEncoder ); if( NTL_SUCCESS != rc ) { if( NTL_ERR_NET_PACKET_PENDING_HEADER == rc || NTL_ERR_NET_PACKET_PENDING_DATA == rc ) { break; } NTL_LOGDL( LOG_NETWORK, "Session[%X] MakeSureCompletedPacket Error[%d:%s]", this, rc, NtlGetErrorMessage(rc) ); return rc; } if( true != IsValidPacket( m_recvBuffer.GetQueueWorkPtr(), wPacketLength ) ) { NTL_LOG_ASSERT("true != IsValidPacket()"); } packet.AttachData( m_recvBuffer.GetQueueWorkPtr(), wPacketLength ); m_recvBuffer.IncreaseWorkPos( packet.GetUsedSize() ); #if __SGPRO_BOTSYSTEM_SENDANDRECVTESTCODE__ #else if( m_pPacketEncoder ) { rc = m_pPacketEncoder->RxDecrypt( packet ); if( NTL_SUCCESS != rc ) { NTL_LOGDL( LOG_NETWORK, "Session[%X] RxDecrypt Error[%d:%s]", this, rc, NtlGetErrorMessage(rc) ); return rc; } } #endif // [9/10/2007 zeroera] : ¼³¸í : sequence°ªÀº 0 ~ 255 BYTE byValidSequence = (BYTE) ( m_dwPacketRecvCount & PACKET_MAX_SEQUENCE ); if( false == HasValidSequence( packet.GetPacketHeader(), byValidSequence ) ) { NTL_LOGDL( LOG_NETWORK, "Session[%X] Sequence Error[%d:%s] PacketSEQ[%u] CurrentSEQ[%u]", this, rc, NtlGetErrorMessage(rc), GetSequence( m_recvBuffer.GetQueueWorkPtr() ), byValidSequence ); return NTL_ERR_NET_PACKET_SEQUENCE_FAIL; } IncreasePacketRecv(); //NTL_PRINT(PRINT_SYSTEM, "Session[%X]\tCompleteRecv Complete recvBufferSize[%d], TotalRecvBytes[%u]", this, m_recvBuffer.GetCurSize(), m_dwTotalRecvSize ); m_pNetworkRef->PostNetEventMessage( (WPARAM)NETEVENT_RECV, (LPARAM)this ); } while( NTL_SUCCESS == rc ); #endif rc = PostRecv(); if( NTL_SUCCESS != rc ) { return rc; } return NTL_SUCCESS; }