aboutsummaryrefslogtreecommitdiff
path: root/src/init.cpp
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2013-04-29 13:25:13 -0700
committerGavin Andresen <gavinandresen@gmail.com>2013-04-29 13:25:13 -0700
commit67f93dc5137ed3f56d65f34172486bd0a716cca4 (patch)
treee0c706a824e5e8c1e29ff71f48a8ca48dab4c4b5 /src/init.cpp
parent228b29cf8f9241df7d4b65c53fbfb59247c78861 (diff)
parentba29a5590bc4479d74454f0b9fdaf007d9d80221 (diff)
Merge pull request #2568 from sipa/rlimit
Try to increase file descriptor rlimit if necessary
Diffstat (limited to 'src/init.cpp')
-rw-r--r--src/init.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/init.cpp b/src/init.cpp
index c42f1aab03..3845cfad81 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)