大家好,又见面了,我是你们的朋友全栈君。
if (-1 == fcntl(iSocketfd, F_SETFL, O_NONBLOCK))
{
printf(“fcntl socket error!\n”);
return -1;
}
int iSocketLen = sizeof(struct sockaddr_in);
/* set recvfrom from server timeout */
struct timeval tv;
fd_set readfds;
for(;;)
{
tv.tv_sec = TIME_OUT_TIME;
tv.tv_usec = 0;
FD_ZERO(&readfds);
FD_SET(iSocketfd, &readfds);
if (select(iSocketfd+1,&readfds,NULL, NULL, &tv) > 0)
{
iRecvNum = recvfrom(iSocketfd,(void *)stRecvBuf,sizeof(*(stRecvBuf)),0, (struct sockaddr *)stRemote,&iSocketLen);
if (-1 == iRecvNum)
{
printf(“received data error!\n”);
}
printf(“iRecvNum is %d\n”,iRecvNum);
}
else
{
printf(“timeout!there is no data arrived!\n”); //return -1
}
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/163456.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...