Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increasing limit of FD_SETSIZE and select

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

like image 219
Vivek Goel Avatar asked Nov 02 '11 06:11

Vivek Goel


People also ask

What is Fd_setsize?

FD_SETSIZE is the #define variable that defines how many file descriptors the various FD macros will use. The default value for FD_SETSIZE is 65534 open file descriptors. This value can not be set greater than OPEN_MAX. For more information, refer to the /usr/include/sys/time. h file.

What is select function in C?

select() The select() call monitors activity on a set of sockets looking for sockets ready for reading, writing, or with an exception condition pending.


1 Answers

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.

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.

like image 197
R.. GitHub STOP HELPING ICE Avatar answered Oct 13 '22 23:10

R.. GitHub STOP HELPING ICE