2 * Copyright (C) 2004, 2007, 2008 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2000, 2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: resource.c,v 1.10 2008/07/11 23:47:09 tbox Exp $ */
24 #include <isc/platform.h>
25 #include <isc/resource.h>
26 #include <isc/result.h>
29 #include "errno2result.h"
32 * Windows limits the maximum number of open files to 2048
35 #define WIN32_MAX_OPEN_FILES 2048
38 isc_resource_setlimit(isc_resource_t resource, isc_resourcevalue_t value) {
39 isc_resourcevalue_t rlim_value;
42 if (resource != isc_resource_openfiles)
43 return (ISC_R_NOTIMPLEMENTED);
46 if (value == ISC_RESOURCE_UNLIMITED)
47 rlim_value = WIN32_MAX_OPEN_FILES;
49 rlim_value = min(value, WIN32_MAX_OPEN_FILES);
51 wresult = _setmaxstdio((int) rlim_value);
54 return (ISC_R_SUCCESS);
56 return (isc__errno2result(errno));
60 isc_resource_getlimit(isc_resource_t resource, isc_resourcevalue_t *value) {
62 if (resource != isc_resource_openfiles)
63 return (ISC_R_NOTIMPLEMENTED);
65 *value = WIN32_MAX_OPEN_FILES;
66 return (ISC_R_SUCCESS);
70 isc_resource_getcurlimit(isc_resource_t resource, isc_resourcevalue_t *value) {
71 return (isc_resource_getlimit(resource, value));