Does CloseHandle() have to be called on threads created with _beginthread()?
Also, I have a question about sockets, with a TCP/IP socket (stream socket), does a single call to recv() get all data waiting on the socket? I have been experimenting and so far I know that it will get 1KB in one big gulp. Does the TCP/IP stack retireve all of the buffer by default.
In case I am not making any sense I will give you a small example
Code:
bool ReadAsciiSocket(SOCKET Sck, char *pData, int nMaxBytes, char cTerm = '\0') {
int nDataPtr = 0, nBufferLeft = nMaxBytes, nLastRead;
memset(pData, 0, nMaxBytes);
while (true) {
nLastRead = recv(Sck, &pData[nDataPtr], nBufferLeft, 0);
if (nLastRead > 0) {
nDataPtr += nLastRead;
nBufferLeft -= nLastRead;
if (pData[nDataPtr - 1] == cTerm) {
return true;
}
} else {
return false;
}
}
}
Is this function above a waste of CPU time, because I have seen some examples that only do this
Code:
int Read( void * pData, unsigned int iLen)
{
if(!pData || !iLen)
return(-1);
return(recv(m_Socket, (char*)pData, iLen, 0));
}
Obviously if this second function will get as many bytes as iLen in one go, it is far better.
Can someone please clarify?
thanks.