diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2013-04-26 00:46:47 +0200 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2013-04-29 01:46:24 +0200 |
commit | ba29a5590bc4479d74454f0b9fdaf007d9d80221 (patch) | |
tree | 3bcafc521d283c9076704dc1aa51400c631ed1eb /src/init.cpp | |
parent | 33029bcedd982f80f7e380bff586f3ab644decce (diff) |
Try to increase file descriptor rlimit if necessary
As the default can be too low, especially on OSX.
Diffstat (limited to 'src/init.cpp')
-rw-r--r-- | src/init.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/init.cpp b/src/init.cpp index 7024f3f785..8efe6dfdcf 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -28,6 +28,15 @@ using namespace boost; CWallet* pwalletMain; CClientUIInterface uiInterface; +#ifdef WIN32 +// Win32 LevelDB doesn't use filedescriptors, and the ones used for +// accessing block files, don't count towards to fd_set size limit +// anyway. +#define MIN_CORE_FILEDESCRIPTORS 0 +#else +#define MIN_CORE_FILEDESCRIPTORS 150 +#endif + // Used to pass flags to the Bind() function enum BindFlags { BF_NONE = 0, @@ -518,6 +527,16 @@ bool AppInit2(boost::thread_group& threadGroup) SoftSetBoolArg("-rescan", true); } + // Make sure enough file descriptors are available + int nBind = std::max((int)mapArgs.count("-bind"), 1); + nMaxConnections = GetArg("-maxconnections", 125); + nMaxConnections = std::max(std::min(nMaxConnections, FD_SETSIZE - nBind - MIN_CORE_FILEDESCRIPTORS), 0); + int nFD = RaiseFileDescriptorLimit(nMaxConnections + MIN_CORE_FILEDESCRIPTORS); + if (nFD < MIN_CORE_FILEDESCRIPTORS) + return InitError(_("Not enough file descriptors available.")); + if (nFD - MIN_CORE_FILEDESCRIPTORS < nMaxConnections) + nMaxConnections = nFD - MIN_CORE_FILEDESCRIPTORS; + // ********************************************************* Step 3: parameter-to-internal-flags fDebug = GetBoolArg("-debug"); @@ -594,6 +613,7 @@ bool AppInit2(boost::thread_group& threadGroup) printf("Startup time: %s\n", DateTimeStrFormat("%Y-%m-%d %H:%M:%S", GetTime()).c_str()); printf("Default data directory %s\n", GetDefaultDataDir().string().c_str()); printf("Used data directory %s\n", strDataDir.c_str()); + printf("Using at most %i connections (%i file descriptors available)\n", nMaxConnections, nFD); std::ostringstream strErrors; if (fDaemon) |