From 5dc2193d2f39773e12085dae1bcf9e6d9568d887 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Wed, 26 Jul 2017 11:11:25 +0200 Subject: [PATCH] Merge #10824: Avoid unnecessary work in SetNetworkActive MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit a2420ae Avoid unnecessary work in SetNetworkActive (João Barbosa) Pull request description: This PR adds an early return to avoid unnecessary notifications when the status doesn't change. Tree-SHA512: 85d05ca6fa36cb581f94bc154d08bd72cd53f6a857173c6fb2f184058f9c0208c4cf5e5d196825a78339902d8f256688eb6793f99abc7be9c7cfac85136180d9 --- src/net.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 27bbf58a98..a5fe513a1e 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2385,16 +2385,18 @@ void CConnman::SetNetworkActive(bool active) { LogPrint(BCLog::NET, "SetNetworkActive: %s\n", active); - if (!active) { - fNetworkActive = false; + if (fNetworkActive == active) { + return; + } + fNetworkActive = active; + + if (!fNetworkActive) { LOCK(cs_vNodes); // Close sockets to all nodes for (CNode* pnode : vNodes) { pnode->CloseSocketDisconnect(); } - } else { - fNetworkActive = true; } uiInterface.NotifyNetworkActiveChanged(fNetworkActive);