免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6284 | 回复: 4
打印 上一主题 下一主题

请问,select返回成功,但是FD_ISSET却返回0为什么? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-01-10 17:57 |只看该作者 |倒序浏览
10可用积分
代码如下:
                        FD_ZERO( &rdset );
                        FD_SET( sockfd, &rdset );
                        
                        tv.tv_sec = sm_read_time;
                        tv.tv_usec = 0;
                        
                        ret = select( sockfd+1, &rdset, NULL, NULL, &tv );
                        
                        if( ret > 0 )
                        {

                                if(FD_ISSET( sockfd, &rdset ) )
                                {// do something normal
                                }
                                 else{ printf("Return 0"); }
                                
                        }

请问 这个是怎么回事儿??select 已经成功返回,而且读集中也只有这么一个fd,为什么FD_ISSET却返回0呢?什么情况发生了呢??谢谢

论坛徽章:
0
2 [报告]
发表于 2008-01-10 18:00 |只看该作者
perror(" ")大法.

论坛徽章:
0
3 [报告]
发表于 2008-01-10 18:34 |只看该作者
不知道是不是这个原因

BUGS

       Under  Linux,  select()  may  report a socket file descriptor as "ready for reading", while nevertheless a
       subsequent read blocks. This could for example happen when data has arrived but upon examination has wrong
       checksum  and  is  discarded. There may be other circumstances.  Thus it may be safer to use O_NONBLOCK on
       sockets that should not block.

论坛徽章:
0
4 [报告]
发表于 2008-01-10 20:15 |只看该作者
要不要查下sockfd是否有效?

论坛徽章:
0
5 [报告]
发表于 2008-01-11 09:58 |只看该作者

回复 #1 greyzp 的帖子

你的sockfd是怎么产生的?先看看这个再说
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP