const void *KClient::GetPackFromServer(unsigned int uLinkId, unsigned int &uLen) { void* pRet = NULL; uLen = 0; do { if (uLinkId >= (unsigned int)m_nMaxConnCount) { ASSERT(FALSE); break; } IKG_SocketStream* pConnection = m_ppConnections[uLinkId]; //ASSERT(pConnection); if (!pConnection) return NULL; timeval sTimeOut = {0, 0}; INT nResult = pConnection->CheckCanRecv(&sTimeOut); if (nResult == 0) { break; } else if (nResult == -1) { // 断线 OnConnectionClose(uLinkId); pConnection->Release(); break; } IKG_Buffer *pBuffer = NULL; nResult = pConnection->Recv(&pBuffer); if (nResult <= 0) { // 断线 OnConnectionClose(uLinkId); pConnection->Release(); break; } LPVOID pData = pBuffer->GetData(); size_t nLen = pBuffer->GetSize(); if (nLen > sizeof(m_szBuffer)) { ASSERT(FALSE); pBuffer->Release(); break; } memcpy(m_szBuffer, pData, nLen); uLen = nLen; pBuffer->Release(); pRet = m_szBuffer; } while(0); return pRet; }
int KClient::Shutdown() { for (int i = 0; i < m_nMaxConnCount; ++i) { IKG_SocketStream* pConnection = m_ppConnections[i]; if (pConnection) { OnConnectionClose((unsigned int)i); pConnection->Release(); m_ppConnections[i] = NULL; } } return 0; }
int KClient::Disconnect(unsigned int uLinkId) { int nRet = INVALID_VALUE; do { if (uLinkId >= (unsigned int)m_nMaxConnCount) { ASSERT(FALSE); break; } IKG_SocketStream* pConnection = m_ppConnections[uLinkId]; if (pConnection == NULL) { //ASSERT(FALSE); break; } OnConnectionClose(uLinkId); pConnection->Release(); nRet = fseye_success; } while(0); return nRet; }
int KClient::SendPackToServer(unsigned int uLinkId, const void *pData, unsigned int uLen) { ASSERT(pData && uLen); int nRet = guard_err; do { if (uLinkId >= (unsigned int)m_nMaxConnCount) { ASSERT(FALSE); break; } IKG_SocketStream* pConnection = m_ppConnections[uLinkId]; if (!pConnection) { // ASSERT(FALSE); break; } IKG_Buffer *pBuffer = KG_MemoryCreateBuffer(uLen); if (!pBuffer) { ASSERT(FALSE); break; } memcpy(pBuffer->GetData(), pData, uLen); INT nResult = pConnection->Send(pBuffer); pBuffer->Release(); if (nResult != 1) { OnConnectionClose(uLinkId); pConnection->Release(); break; } nRet = fseye_success; } while(0); return nRet; }