mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-15 11:36:00 -05:00
init: fixes fd accounting regarding poll/select
We are computing our file descriptors limits based on whether we use poll or select. However, we are taking that into account only partially (subtracting from fd_max in one case, but from nFD later on). Moreover, nBind is also only accounted for partially. Simplify and fix this logic
This commit is contained in:
parent
d661e2b1b7
commit
29008a7ff4
1 changed files with 7 additions and 9 deletions
16
src/init.cpp
16
src/init.cpp
|
@ -993,18 +993,16 @@ bool AppInitParameterInteraction(const ArgsManager& args)
|
||||||
nMaxConnections = std::max(nUserMaxConnections, 0);
|
nMaxConnections = std::max(nUserMaxConnections, 0);
|
||||||
|
|
||||||
nFD = RaiseFileDescriptorLimit(nMaxConnections + MIN_CORE_FILEDESCRIPTORS + MAX_ADDNODE_CONNECTIONS + nBind + NUM_FDS_MESSAGE_CAPTURE);
|
nFD = RaiseFileDescriptorLimit(nMaxConnections + MIN_CORE_FILEDESCRIPTORS + MAX_ADDNODE_CONNECTIONS + nBind + NUM_FDS_MESSAGE_CAPTURE);
|
||||||
|
// If we are using select instead of poll, our actual limit may be even smaller
|
||||||
#ifdef USE_POLL
|
#ifndef USE_POLL
|
||||||
int fd_max = nFD;
|
nFD = std::min(FD_SETSIZE, nFD);
|
||||||
#else
|
|
||||||
int fd_max = FD_SETSIZE;
|
|
||||||
#endif
|
#endif
|
||||||
// Trim requested connection counts, to fit into system limitations
|
|
||||||
// <int> in std::min<int>(...) to work around FreeBSD compilation issue described in #2695
|
|
||||||
nMaxConnections = std::max(std::min<int>(nMaxConnections, fd_max - nBind - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS - NUM_FDS_MESSAGE_CAPTURE), 0);
|
|
||||||
if (nFD < MIN_CORE_FILEDESCRIPTORS)
|
if (nFD < MIN_CORE_FILEDESCRIPTORS)
|
||||||
return InitError(_("Not enough file descriptors available."));
|
return InitError(_("Not enough file descriptors available."));
|
||||||
nMaxConnections = std::min(nFD - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS - NUM_FDS_MESSAGE_CAPTURE, nMaxConnections);
|
|
||||||
|
// Trim requested connection counts, to fit into system limitations
|
||||||
|
// <int> in std::min<int>(...) to work around FreeBSD compilation issue described in #2695
|
||||||
|
nMaxConnections = std::max(std::min<int>(nMaxConnections, nFD - nBind - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS - NUM_FDS_MESSAGE_CAPTURE), 0);
|
||||||
|
|
||||||
if (nMaxConnections < nUserMaxConnections)
|
if (nMaxConnections < nUserMaxConnections)
|
||||||
InitWarning(strprintf(_("Reducing -maxconnections from %d to %d, because of system limitations."), nUserMaxConnections, nMaxConnections));
|
InitWarning(strprintf(_("Reducing -maxconnections from %d to %d, because of system limitations."), nUserMaxConnections, nMaxConnections));
|
||||||
|
|
Loading…
Add table
Reference in a new issue