@@ -927,6 +927,8 @@ void ThreadSocketHandler2(void* parg)
927
927
CAddress addr;
928
928
int nInbound = 0 ;
929
929
930
+ int max_connections = std::min<int >(gArgs .GetArg (" -maxconnections" , 125 ), 950 );
931
+
930
932
if (hSocket != INVALID_SOCKET)
931
933
if (!addr.SetSockAddr ((const struct sockaddr *)&sockaddr))
932
934
LogPrintf (" Warning: Unknown socket family" );
@@ -944,12 +946,11 @@ void ThreadSocketHandler2(void* parg)
944
946
if (nErr != WSAEWOULDBLOCK)
945
947
LogPrintf (" socket error accept INVALID_SOCKET: %d" , nErr);
946
948
}
947
- else if (nInbound >= gArgs . GetArg ( " -maxconnections " , 125 ) - MAX_OUTBOUND_CONNECTIONS)
949
+ else if (nInbound >= max_connections - MAX_OUTBOUND_CONNECTIONS)
948
950
{
949
951
LogPrint (BCLog::LogFlags::NET,
950
- " Surpassed max inbound connections maxconnections:%" PRId64 " minus max_outbound:%i" ,
951
- gArgs .GetArg (" -maxconnections" , 125 ),
952
- MAX_OUTBOUND_CONNECTIONS);
952
+ " Surpassed max inbound connections of %i" ,
953
+ std::max<int >(max_connections - MAX_OUTBOUND_CONNECTIONS, 0 ));
953
954
954
955
closesocket (hSocket);
955
956
}
@@ -1996,15 +1997,17 @@ void StartNode(void* parg)
1996
1997
util::ThreadSetInternalName (" grc-nodestart" );
1997
1998
1998
1999
fShutdown = false ;
1999
- MAX_OUTBOUND_CONNECTIONS = (int )gArgs .GetArg (" -maxoutboundconnections" , 8 );
2000
+ MAX_OUTBOUND_CONNECTIONS = (int ) gArgs .GetArg (" -maxoutboundconnections" , 8 );
2001
+ int max_connections = std::min<int >(gArgs .GetArg (" -maxconnections" , 125 ), 950 );
2000
2002
int nMaxOutbound = 0 ;
2001
2003
if (semOutbound == nullptr ) {
2002
2004
// initialize semaphore
2003
- nMaxOutbound = min (MAX_OUTBOUND_CONNECTIONS, ( int ) gArgs . GetArg ( " -maxconnections " , 125 ) );
2005
+ nMaxOutbound = std:: min< int > (MAX_OUTBOUND_CONNECTIONS, max_connections );
2004
2006
semOutbound = new CSemaphore (nMaxOutbound);
2005
2007
}
2006
2008
2007
- LogPrintf (" Using %i OutboundConnections with a MaxConnections of %" PRId64, MAX_OUTBOUND_CONNECTIONS, gArgs .GetArg (" -maxconnections" , 125 ));
2009
+ LogPrintf (" Using %i OutboundConnections with a MaxConnections of %" PRId64,
2010
+ nMaxOutbound, max_connections);
2008
2011
2009
2012
if (pnodeLocalHost == nullptr )
2010
2013
pnodeLocalHost = new CNode (INVALID_SOCKET, CAddress (CService (" 127.0.0.1" , 0 ), nLocalServices));
0 commit comments