recvfrom()recvfrom()recvfrom()recvfrom()MSG_DONTWAITrecvfrom()recvfrom()

最佳答案:

setsockopt()SO_RCVTIMEOrecvfrom()setsockopt()
#include <sys/types.h> 
#include <sys/socket.h>

...

struct timeval read_timeout;
read_timeout.tv_sec = 0;
read_timeout.tv_usec = 10;
setsockopt(socketfd, SOL_SOCKET, SO_RCVTIMEO, &read_timeout, sizeof read_timeout);

有关on Windows please see here和on Linux see here和/或here (POSIX)的详细信息。