rpc_dtablesize.c revision 7616
1232922Stheraven/*
2232922Stheraven * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3232922Stheraven * unrestricted use provided that this legend is included on all tape
4232922Stheraven * media and as a part of the software program in whole or part.  Users
5232922Stheraven * may copy or modify Sun RPC without charge, but are not authorized
6232922Stheraven * to license or distribute it to anyone else except as part of a product or
7232922Stheraven * program developed by the user.
8232922Stheraven *
9232922Stheraven * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10232922Stheraven * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11232922Stheraven * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
12232922Stheraven *
13232922Stheraven * Sun RPC is provided with no support and without any obligation on the
14232922Stheraven * part of Sun Microsystems, Inc. to assist in its use, correction,
15232922Stheraven * modification or enhancement.
16232922Stheraven *
17232922Stheraven * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18232922Stheraven * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19232922Stheraven * OR ANY PART THEREOF.
20232922Stheraven *
21232922Stheraven * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22232922Stheraven * or profits or other special, indirect and consequential damages, even if
23232922Stheraven * Sun has been advised of the possibility of such damages.
24232922Stheraven *
25232922Stheraven * Sun Microsystems, Inc.
26232922Stheraven * 2550 Garcia Avenue
27227825Stheraven * Mountain View, California  94043
28227825Stheraven */
29227825Stheraven
30227825Stheraven#if defined(LIBC_SCCS) && !defined(lint)
31227825Stheraven/*static char *sccsid = "from: @(#)rpc_dtablesize.c 1.2 87/08/11 Copyr 1987 Sun Micro";*/
32227825Stheraven/*static char *sccsid = "from: @(#)rpc_dtablesize.c	2.1 88/07/29 4.0 RPCSRC";*/
33227825Stheravenstatic char *rcsid = "rpc_dtablesize.c,v 1.1 1994/08/07 18:36:02 wollman Exp";
34227825Stheraven#endif
35227825Stheraven
36227825Stheraven#include <sys/types.h>
37227825Stheraven
38227825Stheraven/*
39227825Stheraven * Cache the result of getdtablesize(), so we don't have to do an
40227825Stheraven * expensive system call every time.
41227825Stheraven */
42227825Stheraven/*
43227825Stheraven * XXX In FreeBSD 2.x, you can have the maximum number of open file
44227825Stheraven * descriptors be greater than FD_SETSIZE (which us 256 by default).
45227825Stheraven * This can lead to many RPC functions getting back an EINVAL from
46227825Stheraven * select() and bombing all over the place.
47227825Stheraven *
48227825Stheraven * You can apparently get select() to handle values larger than 256
49227825Stheraven * by patching the kernel, but most people aren't likely to know
50227825Stheraven * that. Clamping this function at 256 is a kludge, but it'll have to
51227825Stheraven * do until select()'s descriptor table size can be adjusted dynamically.
52227825Stheraven */
53227825Stheraven_rpc_dtablesize()
54227825Stheraven{
55227825Stheraven	static int size;
56227825Stheraven
57227825Stheraven	if (size == 0) {
58227825Stheraven		size = getdtablesize();
59227825Stheraven		if (size > FD_SETSIZE)
60227825Stheraven			size = FD_SETSIZE;
61227825Stheraven	}
62227825Stheraven	return (size);
63227825Stheraven}
64227825Stheraven