免费注册 查看新帖 |

Chinaunix

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

请教 : select 出错返回-1, errno信息为Bad file descriptor [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-01-08 15:39 |只看该作者 |倒序浏览
10可用积分
一个select + 多线程的架构,

一个manager 主线程分发accept到的fd给work子线程(依次生成启动),每个work子线程负载200个fd,

manager和work之间采用pipe进行通信,

每次测试工具启动100 * 25 = 2500个连接(全部建立连接,发送5次4000字节的数据,然后进程sleep, 将fd连接挂住)的时候,

日志显示: manager能全部accept完,并且成功分发到各个线程,pipe显示发送成功

           netstat显示2500个est

但是当到work10的时候,work10在获取到10个socket fd的时候,select返回-1



程序对进程打开文件数的硬限制和软限制均修改为30000, root下运行


请高手指点

最佳答案

查看完整内容

会不会是 FD_SETSIZE 的问题?from UNP v1:int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, const struct timeval *timeout);The constant FD_SETSIZE, defined by including , is the number of descriptors in the fd_set datatype. Its value is often 1024, but few programs use that many descriptors. The maxfdp1 argument forces us to calculate the largest descriptor that we are in ...

论坛徽章:
0
2 [报告]
发表于 2008-01-08 15:39 |只看该作者

回复 #13 unixpm 的帖子

会不会是 FD_SETSIZE 的问题?

from UNP v1:

int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, const struct timeval *timeout);

The constant FD_SETSIZE, defined by including <sys/select.h>, is the number of descriptors in the fd_set datatype. Its value is often 1024, but few programs use that many descriptors. The maxfdp1 argument forces us to calculate the largest descriptor that we are interested in and then tell the kernel this value. For example, given the previous code that turns on the indicators for descriptors 1, 4, and 5, the maxfdp1 value is 6. The reason it is 6 and not 5 is that we are specifying the number of descriptors, not the largest value, and descriptors start at 0.

论坛徽章:
0
3 [报告]
发表于 2008-01-08 15:42 |只看该作者
还有,在每次select前均用fstat检测该fd是否正常,没有出现异常fd

论坛徽章:
0
4 [报告]
发表于 2008-01-08 15:51 |只看该作者
manager和worker不都是线程吗?干嘛还要用pipe通信?

论坛徽章:
0
5 [报告]
发表于 2008-01-08 16:00 |只看该作者
select, 要不你说怎么通信吧,我还不想用pipe呢, 一个线程select多个fd

论坛徽章:
0
6 [报告]
发表于 2008-01-08 16:05 |只看该作者

回复 #4 unixpm 的帖子

传参数、全局变量不都可以吗?线程都是同步的问题,基本不存在通信的问题。

论坛徽章:
0
7 [报告]
发表于 2008-01-08 16:09 |只看该作者
传参数,怎么传?

全局变量?

不要把事情想的那么简单,服务器端模型都是事件驱动的, 你拿什么事件去驱动获取传参数,取全

局变量

论坛徽章:
0
8 [报告]
发表于 2008-01-08 16:18 |只看该作者

回复 #6 unixpm 的帖子

你的线程函数没有参数吗?那个void型的指针你以为干嘛用的?全局的数组,按照索引取值,怎么不能用了?你每个线程处理200个fd,这个不能通过全局数组告诉worker线程吗?用管道在线程间通信,还是头一次见。

论坛徽章:
0
9 [报告]
发表于 2008-01-08 16:25 |只看该作者
返回 -1  你没打errno吗

论坛徽章:
0
10 [报告]
发表于 2008-01-08 16:27 |只看该作者
再说一遍,事件驱动

我还是不清楚你是怎么告诉的
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP