recv after select
-
timeval timeOut;
timeOut.tv_sec = 0;
timeOut.tv_usec = 3000*1000;fd_set fdread, fdExcept;
FD_ZERO(&fdread);
FD_ZERO(&fdExcept);
FD_SET(sock,&fdread);
FD_SET(sock,&fdExcept);int iRet = 0;
iRet = select(0, &fdread, NULL, &fdExcept, &timeOut);if(FD_ISSET(sock,&fdread))
{
//can read
int iRecv = recv(sock, strRecv, 512*1024, 0);// extern char strRecv[512*1024]
/*
If receive buffer has been received 1024 BYTE, recv() no problem. after recv(), iRecv equals 1024.
If receive buffer has been received a lot data, 50*1024 for example, recv() has problem.
strRecv has not got data what is from send() and iRecv not equals 50*1024.
notes: If no select(), only use recv(), that no problem when recv() 50*1024 BYTE
*/
} -
timeval timeOut;
timeOut.tv_sec = 0;
timeOut.tv_usec = 3000*1000;fd_set fdread, fdExcept;
FD_ZERO(&fdread);
FD_ZERO(&fdExcept);
FD_SET(sock,&fdread);
FD_SET(sock,&fdExcept);int iRet = 0;
iRet = select(0, &fdread, NULL, &fdExcept, &timeOut);if(FD_ISSET(sock,&fdread))
{
//can read
int iRecv = recv(sock, strRecv, 512*1024, 0);// extern char strRecv[512*1024]
/*
If receive buffer has been received 1024 BYTE, recv() no problem. after recv(), iRecv equals 1024.
If receive buffer has been received a lot data, 50*1024 for example, recv() has problem.
strRecv has not got data what is from send() and iRecv not equals 50*1024.
notes: If no select(), only use recv(), that no problem when recv() 50*1024 BYTE
*/
} -
timeval timeOut;
timeOut.tv_sec = 0;
timeOut.tv_usec = 3000*1000;fd_set fdread, fdExcept;
FD_ZERO(&fdread);
FD_ZERO(&fdExcept);
FD_SET(sock,&fdread);
FD_SET(sock,&fdExcept);int iRet = 0;
iRet = select(0, &fdread, NULL, &fdExcept, &timeOut);if(FD_ISSET(sock,&fdread))
{
//can read
int iRecv = recv(sock, strRecv, 512*1024, 0);// extern char strRecv[512*1024]
/*
If receive buffer has been received 1024 BYTE, recv() no problem. after recv(), iRecv equals 1024.
If receive buffer has been received a lot data, 50*1024 for example, recv() has problem.
strRecv has not got data what is from send() and iRecv not equals 50*1024.
notes: If no select(), only use recv(), that no problem when recv() 50*1024 BYTE
*/
}As Erwin mentions, you can never assume you'll get all the bytes you request in a single call to recv(). You must keep calling recv() until you get the number of bytes you're expecting. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: