Subject: Re: default maximum number of open file descriptors too small?
To: None <tech-kern@NetBSD.ORG>
From: Christoph Badura <>
List: tech-kern
Date: 11/30/1995 04:01:25
Greg Hudson wrote:
> > I'd rather have the FD_ZERO fixed to take the size of the fd_set as
> > a explicit parameter.

> If we're going to abandon the current select() interface, the right
> answer is to the use the SVR4 poll(), one of the few things System V
> did much better than BSD.

> (There's the minor weakness that it uses a
> millisecond timeout, but that's much less of a flaw than those of the
> select() interface.)

I didn't propose to abandon the current select() interface.  Quite the
contrary, actually.

I don't see a significant functional difference between poll() and
select().  Only minor stylistic differences.  What, exactly, are the
major flaws in the select() interface that poll() hasn't?

Select() isn't going away anytime soon, anyway.

> If someone has a solution that works without changing the current
> select() source-code interface (and I don't think putting an fd_size
> in the fd_set structure truly solves anything), that might be worth
> considering, but tweaking the broken select interface still won't get
> you anything as elegant as poll().

OK, I guess I have to supply more detail:

Create a FD_ZERON(p, n) that takes a fd_mask * and clears n bits worth
of fd_masks.
Create a FD_COPYN(f, t, n) that copys n bits worth of fd_masks from f to
t.  (BTW, why isn't FD_COPY mentioned in the man page?)
Create a FD_ALLOC(n) that malloc()s at least n bits worth of fd_masks.
Hack the old FD_* macros to cast the fd_set * to fd_mask *.

Change the select() prototype to accept void * instead of fd_set *.
(I'd like to have fd_mask * but that's not possible with ANSI C.)

Hack sys_generic.c:select() to do the right thing with dynamically
allocated ibits and obits.

That's all that is necessary and it is fully compatible with the
current interface. Of course, we would lose argument type checking for
select(2) but that isn't a source code compatibility issue.

If one wants to bother with broken programs that examine bits beyond
the specified nfds, that would be trivial to do (e.g., by ensuring that
FD_ALLOC allocates at least FD_SETSIZE worth of fd_masks.)  It's
probably a good idea, not to make strong guarantees about the minimum
size of the area allocated by FD_ALLOC anyway.

Christoph Badura		+49 721 606137

Es genuegt nicht, keine Gedanken zu haben;
man muss auch unfaehig sein, sie auszudruecken.  - Karl Kraus