diff options
author | Chris Moore <dooglus@gmail.com> | 2011-01-23 00:08:09 -0800 |
---|---|---|
committer | Chris Moore <dooglus@gmail.com> | 2011-01-23 00:08:09 -0800 |
commit | 4698dd9a0230a58e8d83eab76315f550e016ec21 (patch) | |
tree | 5fdda6e8315d91a91f66d99084a333f90d4fc854 | |
parent | c90ea2bd6dc76d4b14f747f818ca18b788aa035e (diff) | |
download | bitcoin-4698dd9a0230a58e8d83eab76315f550e016ec21.tar.xz |
Fix -maxconnections. It used to account for the 8 outbound connections twice when calculating the number of slots left for incoming connections.
-rw-r--r-- | net.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
@@ -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); } |