aboutsummaryrefslogtreecommitdiff
path: root/net.cpp
diff options
context:
space:
mode:
authorChris Moore <dooglus@gmail.com>2011-01-23 00:08:09 -0800
committerChris Moore <dooglus@gmail.com>2011-01-23 00:08:09 -0800
commit4698dd9a0230a58e8d83eab76315f550e016ec21 (patch)
tree5fdda6e8315d91a91f66d99084a333f90d4fc854 /net.cpp
parentc90ea2bd6dc76d4b14f747f818ca18b788aa035e (diff)
Fix -maxconnections. It used to account for the 8 outbound connections twice when calculating the number of slots left for incoming connections.
Diffstat (limited to 'net.cpp')
-rw-r--r--net.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/net.cpp b/net.cpp
index a626acd376..bfa6b055a8 100644
--- a/net.cpp
+++ b/net.cpp
@@ -688,12 +688,25 @@ void ThreadSocketHandler2(void* parg)
socklen_t len = sizeof(sockaddr);
SOCKET hSocket = accept(hListenSocket, (struct sockaddr*)&sockaddr, &len);
CAddress addr(sockaddr);
+ bool fLimitConnections = false;
+ int nInbound = 0;
+
+ if (mapArgs.count("-maxconnections"))
+ fLimitConnections = true;
+
+ if (fLimitConnections)
+ {
+ CRITICAL_BLOCK(cs_vNodes)
+ foreach(CNode* pnode, vNodes)
+ if (pnode->fInbound)
+ nInbound++;
+ }
if (hSocket == INVALID_SOCKET)
{
if (WSAGetLastError() != WSAEWOULDBLOCK)
printf("socket error accept failed: %d\n", WSAGetLastError());
}
- else if (mapArgs.count("-maxconnections") && (int)vNodes.size() >= atoi(mapArgs["-maxconnections"]) - MAX_OUTBOUND_CONNECTIONS)
+ else if (fLimitConnections && nInbound >= atoi(mapArgs["-maxconnections"]) - MAX_OUTBOUND_CONNECTIONS)
{
closesocket(hSocket);
}