From edb5350c32cdf7f8487777b5cc1a2ebfcdfc9e75 Mon Sep 17 00:00:00 2001 From: Patrick Strateman Date: Mon, 24 Sep 2018 16:30:53 -0400 Subject: [PATCH] Move NotifyNumConnectionsChanged logic to private method. --- src/net.cpp | 27 ++++++++++++++++----------- src/net.h | 2 ++ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index c51a1b4a7..767275247 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1153,9 +1153,22 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) { } } +void CConnman::NotifyNumConnectionsChanged() +{ + size_t vNodesSize; + { + LOCK(cs_vNodes); + vNodesSize = vNodes.size(); + } + if(vNodesSize != nPrevNodeCount) { + nPrevNodeCount = vNodesSize; + if(clientInterface) + clientInterface->NotifyNumConnectionsChanged(vNodesSize); + } +} + void CConnman::ThreadSocketHandler() { - unsigned int nPrevNodeCount = 0; while (!interruptNet) { // @@ -1219,16 +1232,7 @@ void CConnman::ThreadSocketHandler() } } } - size_t vNodesSize; - { - LOCK(cs_vNodes); - vNodesSize = vNodes.size(); - } - if(vNodesSize != nPrevNodeCount) { - nPrevNodeCount = vNodesSize; - if(clientInterface) - clientInterface->NotifyNumConnectionsChanged(vNodesSize); - } + NotifyNumConnectionsChanged(); // // Find which sockets have data to receive @@ -2217,6 +2221,7 @@ CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In) : nSeed0(nSeed0In), nSe setBannedIsDirty = false; fAddressesInitialized = false; nLastNodeId = 0; + nPrevNodeCount = 0; nSendBufferMaxSize = 0; nReceiveFloodSize = 0; flagInterruptMsgProc = false; diff --git a/src/net.h b/src/net.h index 9f6c426ab..ba5cd4f5c 100644 --- a/src/net.h +++ b/src/net.h @@ -336,6 +336,7 @@ private: void ThreadOpenConnections(std::vector connect); void ThreadMessageHandler(); void AcceptConnection(const ListenSocket& hListenSocket); + void NotifyNumConnectionsChanged(); void ThreadSocketHandler(); void ThreadDNSAddressSeed(); @@ -406,6 +407,7 @@ private: std::list vNodesDisconnected; mutable CCriticalSection cs_vNodes; std::atomic nLastNodeId; + unsigned int nPrevNodeCount; /** Services this instance offers */ ServiceFlags nLocalServices;