From fcd581ec6a17fc01f34b8898f1d0f25815f6171d Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 21 Jul 2026 18:48:40 -0400 Subject: [PATCH] hanlders iterator --- libi2pd_client/I2PService.cpp | 7 ++++--- libi2pd_client/I2PService.h | 10 ++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/libi2pd_client/I2PService.cpp b/libi2pd_client/I2PService.cpp index e3d05022..c7d53bb5 100644 --- a/libi2pd_client/I2PService.cpp +++ b/libi2pd_client/I2PService.cpp @@ -67,9 +67,10 @@ namespace client { if(m_ConnectTimeout) m_ReadyTimer.cancel(); - std::unique_lock l(m_HandlersMutex); - for (auto it: m_Handlers) - it->Terminate (); + IterateHandlers ([](std::shared_ptr handler) + { + if (handler) handler->Terminate (); + }); m_Handlers.clear(); } diff --git a/libi2pd_client/I2PService.h b/libi2pd_client/I2PService.h index 5231a957..4cbb4631 100644 --- a/libi2pd_client/I2PService.h +++ b/libi2pd_client/I2PService.h @@ -74,6 +74,16 @@ namespace client virtual const char* GetName() const { return "Generic I2P Service"; } + protected: + + template + void IterateHandlers (Callback&& callback) + { + std::unique_lock l(m_HandlersMutex); + for (auto it: m_Handlers) + callback (it); + } + private: void TriggerReadyCheckTimer();