int Connections::CompleteSend(DWORD TransferedBytes) { UNREFERENCED_PARAMETER(TransferedBytes); FUNCTION_BEGIN(); IncreaseBytesSend(TransferedBytes); _mutexSend.Lock(); _sendBuffer.IncreasePopPos(TransferedBytes); int rc = 0; if (IsSetControlFlag(CONTROL_FLAG_USE_SEND_QUEUE)) { Packet * SendPacket = _sendQueue.PeekPacket(); while (SendPacket) { if (_sendBuffer.GetPushAvailableSize() <= SendPacket->GetUsedSize()) { break; } BYTE Sequence = (BYTE)(_PacketSendCount & PACKET_MAX_SEQUENCE); SetSequence(SendPacket->GetPacketHeader(), Sequence); if (_PacketEncoder) { rc = _PacketEncoder->TxEncrypt(*SendPacket); if (0 != rc) { _mutexSend.Unlock(); Logger::Log("Session[%X] TxEncrypt Error[%d]\n", this, rc); return 1; //ERR_NET_PACKET_ENCRYPT_FAIL } } memcpy(_sendBuffer.GetQueuePushPtr(), SendPacket->GetPacketBuffer(), SendPacket->GetUsedSize()); _sendBuffer.IncreasePushPos(SendPacket->GetUsedSize()); IncreasePacketSend(); _sendQueue.PopPacket(); SAFE_DELETE(SendPacket); SendPacket = _sendQueue.PeekPacket(); } } if (_sendBuffer.GetCurSize()) { rc = PostSend(); if (0 != rc) { _IsSending = false; _mutexSend.Unlock(); Disconnect(false); Logger::Log("Session[%X] PostSend Error[%d]\n", this, rc); return 0; } } else { _IsSending = false; } _mutexSend.Unlock(); return 0; }
//----------------------------------------------------------------------------------- // Purpose : // Return : //----------------------------------------------------------------------------------- // Called by Worker TH ( IOCP ) //----------------------------------------------------------------------------------- int CNtlConnection::CompleteSend(DWORD dwTransferedBytes) { UNREFERENCED_PARAMETER( dwTransferedBytes ); FUNCTION_BEGIN(); IncreaseBytesSend( dwTransferedBytes ); m_mutexSend.Lock(); m_sendBuffer.IncreasePopPos( dwTransferedBytes ); int rc = 0; if( IsSetControlFlag( CONTROL_FLAG_USE_SEND_QUEUE ) ) { CNtlPacket * pSendPacket = m_sendQueue.PeekPacket(); while( pSendPacket ) { if( m_sendBuffer.GetPushAvailableSize() <= pSendPacket->GetUsedSize() ) { break; } BYTE bySequence = (BYTE) ( m_dwPacketSendCount & PACKET_MAX_SEQUENCE ); SetSequence( pSendPacket->GetPacketHeader(), bySequence ); #if __SGPRO_BOTSYSTEM_SENDANDRECVTESTCODE__ #else if( m_pPacketEncoder ) { rc = m_pPacketEncoder->TxEncrypt( *pSendPacket ); if( NTL_SUCCESS != rc ) { m_mutexSend.Unlock(); NTL_LOGDL( LOG_NETWORK, "Session[%X] TxEncrypt Error[%d:%s]", this, rc, NtlGetErrorMessage(rc) ); return NTL_ERR_NET_PACKET_ENCRYPT_FAIL; } } #endif memcpy( m_sendBuffer.GetQueuePushPtr(), pSendPacket->GetPacketBuffer(), pSendPacket->GetUsedSize() ); m_sendBuffer.IncreasePushPos( pSendPacket->GetUsedSize() ); IncreasePacketSend(); m_sendQueue.PopPacket(); SAFE_DELETE( pSendPacket ); pSendPacket = m_sendQueue.PeekPacket(); } } if( m_sendBuffer.GetCurSize() ) { rc = PostSend(); if( NTL_SUCCESS != rc ) { m_bSending = false; m_mutexSend.Unlock(); // [1/20/2007 zeroera] : ¼³¸í : Send¿¡ ÀÇÇÑ Close ±â´ÉÀ» ¸·À½. TH1ÀÌ Recv Áß¿¡ TH2 °¡ Send ÇÏ¿© CloseÇÏ°Ô µÇ¸é ¹®Á¦°¡ ¹ß»ý ÇÒ ¼ÒÁö°¡ ÀÖÀ½ //return rc; Disconnect( false ); NTL_LOGDL( LOG_NETWORK, "Session[%X] PostSend Error[%d:%s]", this, rc, NtlGetErrorMessage(rc) ); return NTL_SUCCESS; } } else { m_bSending = false; } m_mutexSend.Unlock(); //NTL_PRINT(PRINT_SYSTEM, "Session[%X]\tCompleteSend Complete SendBufferSize[%d] TotalSendBytes[%u]", this, m_sendBuffer.GetCurSize(), m_dwTotalSendSize ); return NTL_SUCCESS; }