diff --git a/src/bsd.c b/src/bsd.c index a70e818..1501de1 100644 --- a/src/bsd.c +++ b/src/bsd.c @@ -153,7 +153,11 @@ kore_platform_event_wait(u_int64_t timer) while (worker_active_connections < worker_max_connections) { - kore_connection_accept(l, &c); + if (!kore_connection_accept(l, &c)) { + r = 1; + break; + } + if (c == NULL) break; diff --git a/src/linux.c b/src/linux.c index bbd5987..47f8f11 100644 --- a/src/linux.c +++ b/src/linux.c @@ -130,7 +130,11 @@ kore_platform_event_wait(u_int64_t timer) while (worker_active_connections < worker_max_connections) { - kore_connection_accept(l, &c); + if (!kore_connection_accept(l, &c)) { + r = 1; + break; + } + if (c == NULL) break; diff --git a/src/worker.c b/src/worker.c index 4d70380..6730a1e 100644 --- a/src/worker.c +++ b/src/worker.c @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -182,6 +183,7 @@ kore_worker_dispatch_signal(int sig) void kore_worker_entry(struct kore_worker *kw) { + size_t fd; struct rlimit rl; char buf[16]; struct connection *c, *cnext; @@ -197,6 +199,16 @@ kore_worker_entry(struct kore_worker *kw) fatal("cannot chdir(): %s", errno_s); } + if (getrlimit(RLIMIT_NOFILE, &rl) == -1) { + kore_log(LOG_WARNING, "getrlimit(RLIMIT_NOFILE): %s", errno_s); + } else { + for (fd = 0; fd < rl.rlim_cur; fd++) { + if (fcntl(fd, F_GETFD, NULL) != -1) { + worker_rlimit_nofiles++; + } + } + } + rl.rlim_cur = worker_rlimit_nofiles; rl.rlim_max = worker_rlimit_nofiles; if (setrlimit(RLIMIT_NOFILE, &rl) == -1) {