Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 16 Nov 1998 21:09:41 +0000 (GMT)
From:      Terry Lambert <tlambert@primenet.com>
To:        bakul@torrentnet.com (Bakul Shah)
Cc:        tlambert@primenet.com, nate@mt.sri.com, hackers@FreeBSD.ORG
Subject:   Re: Supporting more than FD_SETSIZE fd's
Message-ID:  <199811162109.OAA03119@usr08.primenet.com>
In-Reply-To: <199811111344.IAA25228@chai.torrentnet.com> from "Bakul Shah" at Nov 11, 98 08:44:03 am

next in thread | previous in thread | raw e-mail | index | archive | help
> There is a way to select on all the file descriptors your
> program can open.  The idea is to use getdtablesize() to find
> the number of such descriptors and just allocate an array of
> fd_mask.  Something like:
> 
> 	int fd_setsize = getdtablesize();
> 	int fd_tablesize = howmany(max_fd_count, NFDBITS);
> 	fd_mask* readfds = calloc(fd_tablesize, sizeof(fd_mask));
> 	fd_mask* tmp_readfds = calloc(fd_tablesize, sizeof(fd_mask));
> 
> 	...
> 	for (;;) {
> 	    memcpy(tmp_readfds, readfds, fd_tablesize*sizeof(fd_mask));
> 	    int nfds = select(maxfd_in_use+1, tmp_readfds, 0, 0, timeout);


Right.

The problem that normally occurs in naieve net code is this:

	cnt = getdtablesize();
	select( cnt + 1, ...)

The UMICH LDAP server has code like this, and there's a *lot* of
Linux code that operates like this, on the assumption that the
getdtablesize() function will never return more than FD_SETSIZE
number of descriptors.

> Basically fd_set should have never been defined.

Definitely agree.  But... it's *still* stupid to call select with
a count that includes unallocated descriptors.


					Terry Lambert
					terry@lambert.org
---
Any opinions in this posting are my own and not those of my present
or previous employers.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199811162109.OAA03119>