Typo in <sys/select.h>?

Lavrentiev, Anton (NIH/NLM/NCBI) [C] lavr@ncbi.nlm.nih.gov
Wed Jul 6 13:19:02 GMT 2022

> On Linux, select(2) is really only capable to
> handle file descriptors numbers up to descriptor number 1023,

That is not true.  While FD_SETSIZE is defined as a fixed constant,
Linux kernel does not actually "know" (or care) about it.

So you can have an array of fd_sets, like this, in your code:

fd_set r_fds[NFDS];

and then if "fd" is a file descriptor in question, you'd do

FD_SET(fd % FD_SETSIZE, &r_fds[fd / FD_SETSIZE]);

and then

n = select(maxfd + 1, r_fds, ...);

The Linux kernel is guided by the maxfd parameter and assumes the sets are as
large as required to cover that number of file descriptors (obviously checking
that those sets are still within the process reach).

NFDS above is chosen such a way that "NFDS * FD_SETSIZE" covers all your required
file descriptors, if there are more than just FD_SETSIZE.

Anton Lavrentiev
Contractor NIH/NLM/NCBI

More information about the Cygwin mailing list