From: Ben Noordhuis Date: Wed, 2 Oct 2013 10:17:57 +0000 (+0200) Subject: src: raise maximum file descriptor limit X-Git-Tag: v0.11.8~54 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6820054d2d42ff9274ea0755bea59cfc4f26f353;p=platform%2Fupstream%2Fnodejs.git src: raise maximum file descriptor limit Do a binary search for the maximum RLIMIT_NOFILE. Works around the low, low limits on certain high, high-priced devices from Cupertino, CA. --- diff --git a/src/node.cc b/src/node.cc index b736872..9f724d4 100644 --- a/src/node.cc +++ b/src/node.cc @@ -72,6 +72,7 @@ #define umask _umask typedef int mode_t; #else +#include // getrlimit, setrlimit #include // setuid, getuid #endif @@ -3103,6 +3104,28 @@ void Init(int* argc, node_isolate = Isolate::GetCurrent(); #ifdef __POSIX__ + // Raise the open file descriptor limit. + { + struct rlimit lim; + if (getrlimit(RLIMIT_NOFILE, &lim) == 0 && lim.rlim_cur != lim.rlim_max) { + // Do a binary search for the limit. + rlim_t min = lim.rlim_cur; + rlim_t max = 1 << 20; + // But if there's a defined upper bound, don't search, just set it. + if (lim.rlim_max != RLIM_INFINITY) { + min = lim.rlim_max; + max = lim.rlim_max; + } + do { + lim.rlim_cur = min + (max - min) / 2; + if (setrlimit(RLIMIT_NOFILE, &lim)) { + max = lim.rlim_cur; + } else { + min = lim.rlim_cur; + } + } while (min + 1 < max); + } + } // Ignore SIGPIPE RegisterSignalHandler(SIGPIPE, SIG_IGN); RegisterSignalHandler(SIGINT, SignalExit);