From c52a582a3fbb00b61c80aea44fc45dd93cfa2ac8 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Tue, 8 Oct 2024 17:44:00 +0700 Subject: [PATCH] refactor: re-order conditions over flags for m_edge_trig_events - follow-up for bitcoin#21563 --- src/net.cpp | 12 ++++++------ src/util/edge.h | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 67dee39d44..8f88057e78 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -663,8 +663,8 @@ void CNode::CloseSocketDisconnect(CConnman* connman) connman->mapSendableNodes.erase(GetId()); } - if (connman->m_edge_trig_events && !connman->m_edge_trig_events->UnregisterEvents(m_sock->Get())) { - LogPrint(BCLog::NET, "EdgeTriggeredEvents::UnregisterEvents() failed\n"); + if (connman->m_edge_trig_events) { + connman->m_edge_trig_events->UnregisterEvents(m_sock->Get()); } LogPrint(BCLog::NET, "disconnecting peer=%d\n", id); @@ -4310,10 +4310,10 @@ void CConnman::StopNodes() } // Close listening sockets. - for (ListenSocket& hListenSocket : vhListenSocket) { - if (hListenSocket.sock) { - if (m_edge_trig_events && !m_edge_trig_events->RemoveSocket(hListenSocket.sock->Get())) { - LogPrintf("EdgeTriggeredEvents::RemoveSocket() failed\n"); + if (m_edge_trig_events) { + for (ListenSocket& hListenSocket : vhListenSocket) { + if (hListenSocket.sock) { + m_edge_trig_events->RemoveSocket(hListenSocket.sock->Get()); } } } diff --git a/src/util/edge.h b/src/util/edge.h index d1de2f7ba6..1137ce624a 100644 --- a/src/util/edge.h +++ b/src/util/edge.h @@ -17,6 +17,7 @@ enum class SocketEventsMode : int8_t; * A manager for abstracting logic surrounding edge-triggered socket events * modes like kqueue and epoll. */ +// TODO: simplify this class to 2-3 flags; kick out everything else to Sock/~Sock and inherited classes class EdgeTriggeredEvents { public: