select()函数的问题 求大神帮忙解答 为什么select的返回值一直是0 如何才能让它返回大于0的值
FD_ZERO(&readSet);FD_SET(fd,&readSet);printf("%d\n",fd);intiRet=select(fd+1,&readSet,...
FD_ZERO(&readSet);
FD_SET(fd, &readSet);
printf("%d\n",fd);
int iRet = select(fd + 1, &readSet, NULL, NULL, &timeout);
if(iRet == -1)
{
printf("/*SerialPort recv_data select error! */\n");
return -1;
}
else if(iRet == 0)
{
printf("/*SerialPort recv_data select time out! */\n");
return -1;
}
else
{ //等待接收
if(FD_ISSET(fd, &readSet))
{
tmp_len=read(fd, tmp_buf, 1024);
if(tmp_len < 0)
{
printf("/*SerialPort recv_data error! */\n");
return -1;
}
else
{
memcpy(bOutBuf+iOutBufLen, tmp_buf, tmp_len);
iOutBufLen += tmp_len;
memset(tmp_buf,0,1024);
iLen = 105;
if(iOutBufLen ==iLen)
{
//printf("/*SerialPort recv_data sucess:*/\n");
//ShowByte(bOutBuf,iOutBufLen);
return 0;
}
}
}
} 展开
FD_SET(fd, &readSet);
printf("%d\n",fd);
int iRet = select(fd + 1, &readSet, NULL, NULL, &timeout);
if(iRet == -1)
{
printf("/*SerialPort recv_data select error! */\n");
return -1;
}
else if(iRet == 0)
{
printf("/*SerialPort recv_data select time out! */\n");
return -1;
}
else
{ //等待接收
if(FD_ISSET(fd, &readSet))
{
tmp_len=read(fd, tmp_buf, 1024);
if(tmp_len < 0)
{
printf("/*SerialPort recv_data error! */\n");
return -1;
}
else
{
memcpy(bOutBuf+iOutBufLen, tmp_buf, tmp_len);
iOutBufLen += tmp_len;
memset(tmp_buf,0,1024);
iLen = 105;
if(iOutBufLen ==iLen)
{
//printf("/*SerialPort recv_data sucess:*/\n");
//ShowByte(bOutBuf,iOutBufLen);
return 0;
}
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询