When block on receive, we need to set time-out value to unblock.
Here I set 1 second, but not work. //////set time out if blocking
TIMEVAL tout;
tout.tv_sec = 1; //1 second
tout.tv_usec = 0;
fd_set sRead, sWrite;
sRead.fd_count = sWrite.fd_count = 1;
sRead.fd_array[0] = sWrite.fd_array[0] = s;
iRec = select(0, &sRead, &sWrite, NULL, &tout);
/////// while (1){
//would block here
iRec = recv( newSock, arch, sizeof( arch )-1, 0 );
if (iRec == 0 || iRec == SOCKET_ERROR) break; p->m_strReceive += arch;
}
Asking your Help! Thanks!
Here I set 1 second, but not work. //////set time out if blocking
TIMEVAL tout;
tout.tv_sec = 1; //1 second
tout.tv_usec = 0;
fd_set sRead, sWrite;
sRead.fd_count = sWrite.fd_count = 1;
sRead.fd_array[0] = sWrite.fd_array[0] = s;
iRec = select(0, &sRead, &sWrite, NULL, &tout);
/////// while (1){
//would block here
iRec = recv( newSock, arch, sizeof( arch )-1, 0 );
if (iRec == 0 || iRec == SOCKET_ERROR) break; p->m_strReceive += arch;
}
Asking your Help! Thanks!
或者使用异步模式