According to the specification, if nfds
is larger than FD_SETSIZE
, select()
will return -1 and set errno
to EINVAL.
In some implementations (including on Linux systems), it will instead write to bits outside the fd_set
structure, potentially corrupting memory in your application. (The intent is to allow applications to use larger fd_set
structures, but the effect is often to cause applications to crash as soon as they try to use more than 1024 file descriptors.)
To work with more than 1024 file descriptors, you will need to use an API other than select()
. These APIs are often system-specific; one platform-independent option to consider is the libev library, which provides a set of useful abstractions for highly concurrent applications.