Increasing limit of FD_SETSIZE and select

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.

Leave a Comment