Date: Wed, 11 Nov 1998 15:03:13 -0800 From: Don Lewis <Don.Lewis@tsc.tdk.com> To: Bakul Shah <bakul@torrentnet.com>, Terry Lambert <tlambert@primenet.com> Cc: nate@mt.sri.com (Nate Williams), hackers@FreeBSD.ORG Subject: Re: Supporting more than FD_SETSIZE fd's Message-ID: <199811112303.PAA02167@salsa.gv.tsc.tdk.com> In-Reply-To: Bakul Shah <bakul@torrentnet.com> "Re: Supporting more than FD_SETSIZE fd's" (Nov 11, 8:44am)
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199811112303.PAA02167>