Merge #10824: Avoid unnecessary work in SetNetworkActive
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
This commit is contained in:
commit
9dd6a2be41
1 changed files with 6 additions and 4 deletions
10
src/net.cpp
10
src/net.cpp
|
@ -2183,16 +2183,18 @@ void CConnman::SetNetworkActive(bool active)
|
||||||
{
|
{
|
||||||
LogPrint(BCLog::NET, "SetNetworkActive: %s\n", active);
|
LogPrint(BCLog::NET, "SetNetworkActive: %s\n", active);
|
||||||
|
|
||||||
if (!active) {
|
if (fNetworkActive == active) {
|
||||||
fNetworkActive = false;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fNetworkActive = active;
|
||||||
|
|
||||||
|
if (!fNetworkActive) {
|
||||||
LOCK(cs_vNodes);
|
LOCK(cs_vNodes);
|
||||||
// Close sockets to all nodes
|
// Close sockets to all nodes
|
||||||
for (CNode* pnode : vNodes) {
|
for (CNode* pnode : vNodes) {
|
||||||
pnode->CloseSocketDisconnect();
|
pnode->CloseSocketDisconnect();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
fNetworkActive = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uiInterface.NotifyNetworkActiveChanged(fNetworkActive);
|
uiInterface.NotifyNetworkActiveChanged(fNetworkActive);
|
||||||
|
|
Loading…
Reference in a new issue