public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: "Lavrentiev, Anton (NIH/NLM/NCBI) [C]" <lavr@ncbi.nlm.nih.gov>
To: "cygwin@cygwin.com" <cygwin@cygwin.com>
Subject: Re: Typo in <sys/select.h>?
Date: Wed, 6 Jul 2022 13:19:02 +0000	[thread overview]
Message-ID: <DM8PR09MB70957DF0C3E4AB75B8FCC2D2A5809@DM8PR09MB7095.namprd09.prod.outlook.com> (raw)

> 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

             reply	other threads:[~2022-07-06 13:19 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-06 13:19 Lavrentiev, Anton (NIH/NLM/NCBI) [C] [this message]
2022-07-06 14:17 ` Corinna Vinschen
  -- strict thread matches above, loose matches on Subject: below --
2022-07-06 15:57 Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2022-07-06 17:03 ` Ken Brown
2022-07-06 14:26 Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2022-07-06 15:07 ` Corinna Vinschen
2022-07-06 14:17 Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2022-07-05 15:11 Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2022-07-05 14:13 Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2022-07-05 14:55 ` Andrey Repin
2022-07-05 21:51 ` Ken Brown
2022-07-06  7:42   ` Corinna Vinschen
2022-07-06 14:01     ` Jon Turney
2022-07-06 14:15       ` Corinna Vinschen
2022-07-06 14:22         ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DM8PR09MB70957DF0C3E4AB75B8FCC2D2A5809@DM8PR09MB7095.namprd09.prod.outlook.com \
    --to=lavr@ncbi.nlm.nih.gov \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).