From owner-freebsd-hackers Wed Nov 11 15:09:27 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id PAA15763 for freebsd-hackers-outgoing; Wed, 11 Nov 1998 15:09:27 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from gatekeeper.tsc.tdk.com (gatekeeper.tsc.tdk.com [207.113.159.21]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id PAA15757 for ; Wed, 11 Nov 1998 15:09:25 -0800 (PST) (envelope-from gdonl@tsc.tdk.com) Received: from sunrise.gv.tsc.tdk.com (root@sunrise.gv.tsc.tdk.com [192.168.241.191]) by gatekeeper.tsc.tdk.com (8.8.8/8.8.8) with ESMTP id PAA00287; Wed, 11 Nov 1998 15:03:15 -0800 (PST) (envelope-from gdonl@tsc.tdk.com) Received: from salsa.gv.tsc.tdk.com (salsa.gv.tsc.tdk.com [192.168.241.194]) by sunrise.gv.tsc.tdk.com (8.8.5/8.8.5) with ESMTP id PAA05648; Wed, 11 Nov 1998 15:03:14 -0800 (PST) Received: (from gdonl@localhost) by salsa.gv.tsc.tdk.com (8.8.5/8.8.5) id PAA02167; Wed, 11 Nov 1998 15:03:13 -0800 (PST) From: Don Lewis Message-Id: <199811112303.PAA02167@salsa.gv.tsc.tdk.com> Date: Wed, 11 Nov 1998 15:03:13 -0800 In-Reply-To: Bakul Shah "Re: Supporting more than FD_SETSIZE fd's" (Nov 11, 8:44am) X-Mailer: Mail User's Shell (7.2.6 alpha(3) 7/19/95) To: Bakul Shah , Terry Lambert Subject: Re: Supporting more than FD_SETSIZE fd's Cc: nate@mt.sri.com (Nate Williams), hackers@FreeBSD.ORG Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Nov 11, 8:44am, Bakul Shah wrote: } Subject: Re: Supporting more than FD_SETSIZE fd's } 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)); You may not want to do this. Some implementations return may return very large numbers from getdtablesize(), like INT_MAX. I've heard bug reports about software that wants to close all fds other than 0, 1, and 2 between a fork() and an exec(), and it does so by looping over all the numbers from 3 to the return value from getdtablesize() and executing close() on each. This is horribly slow if getdtablesize() returns an unreasonably large number. What you could do is allocate your fd_masks based on maxfd_in_use plus some slop and reallocate it to a larger size whenever maxfd_in_use increases enough to make it necessary. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message