如何使recv调用不阻塞并使其仅等待5秒!
// Receive until the peer closes the connection
do {
iResult = recv(ConnectSocket, recvbuf, recvbuflen, 0);
if ( iResult > 0 )
printf("Bytes received: %dn", iResult);
else if ( iResult == 0 )
printf("Connection closedn");
else
printf("recv failed with error: %dn", WSAGetLastError());
} while( iResult > 0 );
fd_set readfds;
struct timeval count;
FD_ZERO(&readfds);
FD_SET(sockfd, &readfds);
select(0, &readfds, 0, 0, &count);
if (FD_ISSET(sockfd, &readfds))
{
if ((bytes=recv(sockfd, buffer2, 200, 0)) == -1) {
return 0;
}
}