1 /*
2 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, you can obtain one at https://mozilla.org/MPL/2.0/.
7 *
8 * See the COPYRIGHT file distributed with this work for additional
9 * information regarding copyright ownership.
10 */
11
12
13 #include <config.h>
14
15 #include <stdio.h>
16
17 #include <isc/platform.h>
18 #include <isc/resource.h>
19 #include <isc/result.h>
20 #include <isc/util.h>
21
22 #include "errno2result.h"
23
24 /*
25 * Windows limits the maximum number of open files to 2048
26 */
27
28 #define WIN32_MAX_OPEN_FILES 2048
29
30 isc_result_t
isc_resource_setlimit(isc_resource_t resource,isc_resourcevalue_t value)31 isc_resource_setlimit(isc_resource_t resource, isc_resourcevalue_t value) {
32 isc_resourcevalue_t rlim_value;
33 int wresult;
34
35 if (resource != isc_resource_openfiles)
36 return (ISC_R_NOTIMPLEMENTED);
37
38
39 if (value == ISC_RESOURCE_UNLIMITED)
40 rlim_value = WIN32_MAX_OPEN_FILES;
41 else
42 rlim_value = min(value, WIN32_MAX_OPEN_FILES);
43
44 wresult = _setmaxstdio((int) rlim_value);
45
46 if (wresult > 0)
47 return (ISC_R_SUCCESS);
48 else
49 return (isc__errno2result(errno));
50 }
51
52 isc_result_t
isc_resource_getlimit(isc_resource_t resource,isc_resourcevalue_t * value)53 isc_resource_getlimit(isc_resource_t resource, isc_resourcevalue_t *value) {
54
55 if (resource != isc_resource_openfiles)
56 return (ISC_R_NOTIMPLEMENTED);
57
58 *value = WIN32_MAX_OPEN_FILES;
59 return (ISC_R_SUCCESS);
60 }
61
62 isc_result_t
isc_resource_getcurlimit(isc_resource_t resource,isc_resourcevalue_t * value)63 isc_resource_getcurlimit(isc_resource_t resource, isc_resourcevalue_t *value) {
64 return (isc_resource_getlimit(resource, value));
65 }
66