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 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.
select() The select() call monitors activity on a set of sockets looking for sockets ready for reading, writing, or with an exception condition pending.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With