The man page for select() states:
WARNING:
select()can monitor only file descriptors numbers that are less thanFD_SETSIZE(1024)—an unreasonably low limit for many modern applications.
This is very vague, I understand that select can only monitor 1024 file descriptors, but what if I want it to monitor a single file descriptor, a descriptor with an integer value greater than 1024.
For context, I am writing a program that has a timeout on a file descriptor of 15 seconds, and this file descriptor may have an integer value greater than 1024. From what I heard a few months ago, select() seems like a prime choice for this task.
I will only be monitoring one file descriptor, say it is called int fd and fd == 65533. Can select watch this single descriptor 65533?
The manpage might give you the impression that 1024 is a hard upper limit for
select, but that's not true. Some C libraries let you#define FD_SETSIZEyourself, before includingsys/select.h, and thus enlargefd_set. Even if you don't have one of those C libraries, nothing stops you from defining your own, larger fd_set-like data type. The kernel does not know how big the C library definedfd_setto be: instead it trusts thenfdsargument to tell it how many bits there are.However, if you only have one fd to monitor, you should definitely use
poll()instead ofselect(), because it's both simpler to use, and more efficient, for small numbers of fds. And if you have many fds to monitor,epollorkqueueor similar will be more efficient than eitherpollorselect. So it usually isn't worth bothering to work around the size offd_set.