Don't wake up select if it was already woken up (#2863)

This avoids calling WakeupSelect() for each node instead of just once.
This commit is contained in:
Alexander Block 2019-04-12 12:58:42 +02:00 committed by UdjinM6
parent 7fe1a4a78b
commit fbe44761c0
2 changed files with 6 additions and 4 deletions

View File

@ -1321,10 +1321,10 @@ void CConnman::ThreadSocketHandler()
}
}
isInSelect = true;
wakeupSelectNeeded = true;
int nSelect = select(have_fds ? hSocketMax + 1 : 0,
&fdsetRecv, &fdsetSend, &fdsetError, &timeout);
isInSelect = false;
wakeupSelectNeeded = false;
if (interruptNet)
return;
@ -1521,6 +1521,8 @@ void CConnman::WakeSelect()
LogPrint("net", "write to wakeupPipe failed\n");
}
#endif
wakeupSelectNeeded = false;
}
@ -3236,7 +3238,7 @@ void CConnman::PushMessage(CNode* pnode, CSerializedNetMsg&& msg, bool allowOpti
if (optimisticSend == true)
nBytesSent = SocketSendData(pnode);
// wake up select() call in case there was no pending data before (so it was not selecting this socket for sending)
else if (!hasPendingData && isInSelect)
else if (!hasPendingData && wakeupSelectNeeded)
WakeSelect();
}
if (nBytesSent)

View File

@ -546,7 +546,7 @@ private:
/** a pipe which is added to select() calls to wakeup before the timeout */
int wakeupPipe[2]{-1,-1};
#endif
std::atomic<bool> isInSelect{false};
std::atomic<bool> wakeupSelectNeeded{false};
std::thread threadDNSAddressSeed;
std::thread threadSocketHandler;