麻烦各位大侠帮忙看看这个套接字数据发送函数是否可靠吗?
////////////////////////////////////////////////////////////////////////////////////////////////////////// NAME: YESUN LONG (龙丕广)(QQ: 964148807)
////////////////////////////////////////////////////////////////////////////////////////////////////////
bool CSOCKET::Send(CMSG &cMsg)
{
CMemFile* pFile = new CMemFile; cMsg.WriteOutToFile(*pFile);
BYTE* pData = pFile->Detach(); BYTE* pBPointer = pData;
int iCb = 0; UINT iTLen = ((long*)pData)[0], iBKTLen = iTLen;
for (;;){
if (SOCKET_ERROR==(iCb=send(m_hSocket,(char*)pData,iTLen,0))){
if (m_iIDUser>0){
CString S; S.Format(" 发包出错,损坏包已发(%d[B]).",pData-pBPointer); ShowMessage(S,0,0);
}
closesocket(m_hSocket); m_hSocket = INVALID_SOCKET;
free(pBPointer); delete pFile; m_iTUsed = ::GetTickCount();
return false;
}
pData += iCb; iTLen -= iCb;
if (iTLen==0){ break; }
}
delete pFile; free(pBPointer); m_iTUsed = ::GetTickCount();
return true;
}