196#ifndef HAVE_GETRLIMIT
197#if defined(CYGWIN) || defined(__CYGWIN__)
198 const char *platform =
"Cygwin";
199 const unsigned long MAX_CONNECTIONS = 3200;
201 const char *platform =
"Windows";
202 const unsigned long MAX_CONNECTIONS = 15000;
204 const char *platform =
"unknown platforms with no getrlimit()";
205 const unsigned long MAX_CONNECTIONS = 15000;
208 "This platform is missing getrlimit(). Proceeding.");
209 if (limit > MAX_CONNECTIONS) {
211 "We do not support more than %lu file descriptors "
212 "on %s. Tried to raise to %lu.",
213 (
unsigned long)MAX_CONNECTIONS, platform, (
unsigned long)limit);
216 limit = MAX_CONNECTIONS;
220 if (getrlimit(RLIMIT_NOFILE, &rlim) != 0) {
221 log_warn(
LD_NET,
"Could not get maximum number of file descriptors: %s",
225 if (rlim.rlim_max < limit) {
226 log_warn(
LD_CONFIG,
"We need %lu file descriptors available, and we're "
227 "limited to %lu. Please change your ulimit -n.",
228 (
unsigned long)limit, (
unsigned long)rlim.rlim_max);
232 if (rlim.rlim_max > rlim.rlim_cur) {
233 log_info(
LD_NET,
"Raising max file descriptors from %lu to %lu.",
234 (
unsigned long)rlim.rlim_cur, (
unsigned long)rlim.rlim_max);
240 rlim.rlim_cur = rlim.rlim_max;
242 if (setrlimit(RLIMIT_NOFILE, &rlim) != 0) {
244 const int setrlimit_errno = errno;
247 if (errno == EINVAL && try_limit < (uint64_t) rlim.rlim_cur) {
250 rlim.rlim_cur = MIN((rlim_t) try_limit, rlim.rlim_cur);
251 if (setrlimit(RLIMIT_NOFILE, &rlim) == 0) {
252 if (rlim.rlim_cur < (rlim_t)limit) {
253 log_warn(
LD_CONFIG,
"We are limited to %lu file descriptors by "
254 "OPEN_MAX (%lu), and ConnLimit is %lu. Changing "
256 (
unsigned long)try_limit, (
unsigned long)OPEN_MAX,
257 (
unsigned long)limit);
259 log_info(
LD_CONFIG,
"Dropped connection limit to %lu based on "
260 "OPEN_MAX (%lu); Apparently, %lu was too high and rlimit "
262 (
unsigned long)try_limit, (
unsigned long)OPEN_MAX,
263 (
unsigned long)rlim.rlim_max);
270 log_warn(
LD_CONFIG,
"Couldn't set maximum number of file descriptors: %s",
271 strerror(setrlimit_errno));
275 limit = rlim.rlim_cur;