BOOL KLogClient::ProcessPackage() { BOOL bResult = false; int nRetCode = false; IKG_Buffer* piBuffer = NULL; KG_PROCESS_ERROR(m_piSocketStream); while (true) { const struct timeval TimeVal = {0, 0}; INTERNAL_PROTOCOL_HEADER* pHeader = NULL; size_t uPakSize = 0; PROCESS_PROTOCOL_FUNC pFunc = NULL; if (g_pSO3World->m_nCurrentTime - m_nLastSendPacketTime > m_nPingCycle) { DoPingSignal(); } nRetCode = m_piSocketStream->CheckCanRecv(&TimeVal); if (nRetCode == -1) { m_bSocketError = true; goto Exit0; } if (nRetCode == 0) { break; } KGLOG_PROCESS_ERROR(nRetCode == 1); KG_COM_RELEASE(piBuffer); nRetCode = m_piSocketStream->Recv(&piBuffer); if (nRetCode == -1) { m_bSocketError = true; goto Exit0; } KGLOG_PROCESS_ERROR(nRetCode == 1); pHeader = (INTERNAL_PROTOCOL_HEADER*)piBuffer->GetData(); KGLOG_PROCESS_ERROR(pHeader); KGLOG_PROCESS_ERROR(pHeader->wProtocolID < l2g_protocol_end); uPakSize = piBuffer->GetSize(); KGLOG_PROCESS_ERROR(uPakSize >= m_uProtocolSize[pHeader->wProtocolID]); pFunc = m_ProcessProtocolFuns[pHeader->wProtocolID]; if (pFunc == NULL) { KGLogPrintf(KGLOG_INFO, "Protocol %d not process!", pHeader->wProtocolID); goto Exit0; } (this->*pFunc)((BYTE*)pHeader, uPakSize); } bResult = true; Exit0: if (m_piSocketStream && m_bSocketError) { KGLogPrintf(KGLOG_ERR, "Log server connection lost!\n"); KG_COM_RELEASE(m_piSocketStream); } KG_COM_RELEASE(piBuffer); return bResult; }
BOOL KApexProxy::Breathe() { BOOL bResult = false; int nRetCode = false; IKG_Buffer* piBuffer = NULL; BOOL bConnectionAlive = true; BYTE* pbyRecvData = NULL; size_t uRecvDataLen = 0; // if (m_piSocketStream == NULL) // Try Connect // { // nRetCode = Connect( // g_pSO3GameCenter->m_Settings.m_szApexServerIP, // g_pSO3GameCenter->m_Settings.m_nApexServerPort // ); // KG_PROCESS_ERROR(nRetCode); // } KG_PROCESS_ERROR(m_piSocketStream); // assert(m_piSocketStream); if (m_bSendErrorFlag) { bConnectionAlive = false; m_bSendErrorFlag = false; goto Exit0; } while (true) { timeval TimeVal = {0, 0}; if (g_pSO3GameCenter->m_nTimeNow - m_nLastPingTime > g_pSO3GameCenter->m_Settings.m_nApexPingCycle) { DoPingSignal(); m_nLastPingTime = g_pSO3GameCenter->m_nTimeNow; } nRetCode = m_piSocketStream->CheckCanRecv(&TimeVal); if (nRetCode == -1) { bConnectionAlive = false; goto Exit0; } if (nRetCode == 0) { break; } KGLOG_PROCESS_ERROR(nRetCode == 1); KG_COM_RELEASE(piBuffer); nRetCode = m_piSocketStream->Recv(&piBuffer); if (nRetCode == -1) { bConnectionAlive = false; goto Exit0; } KGLOG_PROCESS_ERROR(nRetCode == 1); pbyRecvData = (BYTE*)piBuffer->GetData(); KGLOG_PROCESS_ERROR(pbyRecvData); uRecvDataLen = piBuffer->GetSize(); ProcessRecvData(pbyRecvData, uRecvDataLen); } ClearTimeoutKickNode(); bResult = true; Exit0: if (m_piSocketStream && !bConnectionAlive) { KGLogPrintf(KGLOG_INFO, "[ApexProxy] Connection lost."); KG_COM_RELEASE(m_piSocketStream); } KG_COM_RELEASE(piBuffer); return bResult; }