*BSD News Article 88654


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!lucy.swin.edu.au!news.rmit.EDU.AU!goanna.cs.rmit.edu.au!news.apana.org.au!cantor.edge.net.au!news.teragen.com.au!news.access.net.au!news.mel.connect.com.au!munnari.OZ.AU!spool.mu.edu!howland.erols.net!www.nntp.primenet.com!nntp.primenet.com!data.ramona.vix.com!vixie!nnrp.vix.com!vixie
From: vixie@vix.com (Paul A Vixie)
Newsgroups: comp.unix.bsd.netbsd.misc
Subject: Ouch!  (NetBSD 1.2 select() only allows for 256 descriptors)
Followup-To: comp.unix.bsd.netbsd.misc
Date: 08 Feb 1997 04:28:11 GMT
Organization: Vixie Enterprises
Lines: 50
Message-ID: <VIXIE.97Feb7202811@wisdom.vix.com>
NNTP-Posting-Host: wisdom.home.vix.com
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.netbsd.misc:5323

I was getting these strange EINVALs back from select() when trying to do
a select() on more than 256 descriptors.  I checked NetBSD 1.2 and saw the
horrible old 4.4BSD version of sys_select():

/*
 * Select system call.
 */
int
sys_select(p, v, retval)
        register struct proc *p;
        void *v;
        register_t *retval;
{
        register struct sys_select_args /* {
                syscallarg(u_int) nd;
                syscallarg(fd_set *) in;
                syscallarg(fd_set *) ou;
                syscallarg(fd_set *) ex;
                syscallarg(struct timeval *) tv;
        } */ *uap = v;
        fd_set ibits[3], obits[3];
        struct timeval atv;
        int s, ncoll, error = 0, timo;
        u_int ni;

        bzero((caddr_t)ibits, sizeof(ibits));
        bzero((caddr_t)obits, sizeof(obits));
        if (SCARG(uap, nd) > FD_SETSIZE)
                return (EINVAL);
        if (SCARG(uap, nd) > p->p_fd->fd_nfiles) {
                /* forgiving; slightly wrong */
                SCARG(uap, nd) = p->p_fd->fd_nfiles;
        }
        ni = howmany(SCARG(uap, nd), NFDBITS) * sizeof(fd_mask);
...

So, OK, sure, I recompiled the kernel with

	options FD_SETSIZE=4096

...and now my application isn't wiping out any more.  But those bzero()'s
just got a lot more expensive for everybody, even little itty bitty telnetd's
with 5 descriptors total.

Has anybody given any thought to a little creative use of malloc() here?
-- 
Paul Vixie
La Honda, CA			"Illegitimibus non carborundum."
<paul@vix.com>
pacbell!vixie!paul