FD_SETSIZE并选择增加限制 [英] Increasing limit of FD_SETSIZE and select

查看:2128
本文介绍了FD_SETSIZE并选择增加限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提高FD_SETSIZE宏值我的系统。
有什么办法来增加FD_SETSIZE所以选择不会失败

I want to increase FD_SETSIZE macro value for my system. Is there any way to increase FD_SETSIZE so select will not fail

推荐答案

每标准,没有办法增加 FD_SETSIZE 。某些程序和库(libevent的想到)尝试为 FD_SET 对象分配额外的空间,通过较大的值比 FD_SETSIZE FD _ * 宏,但是这是一个非常糟糕的主意,因为强大的实现可能的参数执行边界检查和中止如果它是超出范围。

Per the standards, there is no way to increase FD_SETSIZE. Some programs and libraries (libevent comes to mind) try to work around this by allocating additional space for the fd_set object and passing values larger than FD_SETSIZE to the FD_* macros, but this is a very bad idea since robust implementations may perform bounds-checking on the argument and abort if it's out of range.

我有一个替代的解决方案,应始终正常工作(即使它不是由标准的要求)。相反,一个 FD_SET 的对象,分配他们的大到足以容纳最大FD你需要,那么使用数组 FD_SET(FD%FD_SETSIZE ,&安培; fds_array [FD / FD_SETSIZE])等访问设置

I have an alternate solution that should always work (even though it's not required to by the standards). Instead of a single fd_set object, allocate an array of them large enough to hold the max fd you'll need, then use FD_SET(fd%FD_SETSIZE, &fds_array[fd/FD_SETSIZE]) etc. to access the set.

这篇关于FD_SETSIZE并选择增加限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆