On 7/5/2022 10:13 AM, Lavrentiev, Anton (NIH/NLM/NCBI) [C] via Cygwin wrote:
Hi,

There's some inconsistency between <sys/select.h> and <sys/param.h>:

sys/select.h has this:
-----------------------
/*
  * Select uses bit masks of file descriptors in longs.
  * These macros manipulate such bit fields (the filesystem macros use chars).
  * FD_SETSIZE may be defined by the user, but the default here
  * should be >= NOFILE (param.h).
  */
#ifndef FD_SETSIZE
#define FD_SETSIZE      64
#endif
----------------------

I think Cygwin's FD macros are based on FreeBSD. The most recent <sys/select.h> on FreeBSD says:

---------------------------------------------------------------------
/*
 * Select uses bit masks of file descriptors in longs.  These macros
 * manipulate such bit fields (the filesystem macros use chars).
 * FD_SETSIZE may be defined by the user, but the default here should
 * be enough for most uses.
 */
#ifndef FD_SETSIZE
#define FD_SETSIZE      1024
#endif
---------------------------------------------------------------------

NOFILE isn't mentioned. Maybe Cygwin (or really newlib) should also remove the reference to NOFILE and, perhaps, change the default FD_SETSIZE to 1024. But Cygwin isn't the only newlib target, so there might be good reasons to keep it at 64.

Corinna, WDYT?  Or should the discussion be moved to the newlib list?

Now, this is the relevant part of sys/param.h looks like this:
----------------------
/* Max number of open files.  The Posix version is OPEN_MAX.  */
/* Number of fds is virtually unlimited in cygwin, but we must provide
    some reasonable value for Posix conformance */
#define NOFILE          8192
----------------------

So it's either "<= NOFILE" that was actually meant to be there in the comment 
(or,
an equivalent "should NOT be > NOFILE"), or FD_SETSIZE should have been defined 
as 8192,
if the comment is actually correct.  Or maybe I'm missing something here :-)

I suspect that the comment was actually meant as written. On FreeBSD, NOFILE is defined to be OPEN_MAX, which is 64. On Cygwin, however, it wouldn't make sense to follow that comment since, as noted in your quote from sys/param.h, there is effectively no limit on open files on Cygwin. (Cygwin maintains a dynamically growing table of file descriptors.)

Ken

--
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

Reply via email to