From efb6faefb0e5856b2ac105548fde7e593cfbf85e Mon Sep 17 00:00:00 2001 From: evoskuil Date: Sat, 16 May 2026 13:43:33 -0400 Subject: [PATCH] Make logger un/subscribe mutable. --- include/bitcoin/network/log/logger.hpp | 11 ++++++----- src/log/logger.cpp | 9 +++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/bitcoin/network/log/logger.hpp b/include/bitcoin/network/log/logger.hpp index 123e47d96..594dbcf32 100644 --- a/include/bitcoin/network/log/logger.hpp +++ b/include/bitcoin/network/log/logger.hpp @@ -112,8 +112,8 @@ class BCT_API logger final /// If stopped, handler is invoked with error::subscriber_stopped/defaults /// and dropped. Otherwise it is held until stop/drop. False if failed. - void subscribe_messages(message_notifier&& handler) NOEXCEPT; - void subscribe_events(event_notifier&& handler) NOEXCEPT; + void subscribe_messages(message_notifier&& handler) const NOEXCEPT; + void subscribe_events(event_notifier&& handler) const NOEXCEPT; /// Stop subscribers/pool with final message/empty posted to subscribers. void stop(const code& ec, const std::string& message, uint8_t level) NOEXCEPT; @@ -127,11 +127,12 @@ class BCT_API logger final std::string&& message) const NOEXCEPT; private: - void do_subscribe_messages(const message_notifier& handler) NOEXCEPT; + void do_subscribe_messages( + const message_notifier& handler) const NOEXCEPT; void do_notify_message(const code& ec, uint8_t level, time_t zulu, const std::string& message) const NOEXCEPT; - void do_subscribe_events(const event_notifier& handler) NOEXCEPT; + void do_subscribe_events(const event_notifier& handler) const NOEXCEPT; void do_notify_event(uint8_t event, uint64_t value, const time& point) const NOEXCEPT; @@ -144,7 +145,7 @@ class BCT_API logger final // These are thread safe. std::atomic_bool stopped_{ false }; BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) - asio::strand strand_{ pool_.service().get_executor() }; + mutable asio::strand strand_{ pool_.service().get_executor() }; BC_POP_WARNING() // These are protected by strand. diff --git a/src/log/logger.cpp b/src/log/logger.cpp index 6934ff9e9..fb9b1f157 100644 --- a/src/log/logger.cpp +++ b/src/log/logger.cpp @@ -119,7 +119,7 @@ void logger::do_notify_message(const code& ec, uint8_t level, time_t zulu, message_subscriber_.notify(ec, level, zulu, message); } -void logger::subscribe_messages(message_notifier&& handler) NOEXCEPT +void logger::subscribe_messages(message_notifier&& handler) const NOEXCEPT { if (stopped()) { @@ -133,7 +133,8 @@ void logger::subscribe_messages(message_notifier&& handler) NOEXCEPT } // private -void logger::do_subscribe_messages(const message_notifier& handler) NOEXCEPT +void logger::do_subscribe_messages( + const message_notifier& handler) const NOEXCEPT { BC_ASSERT(stranded()); message_subscriber_.subscribe(move_copy(handler)); @@ -157,7 +158,7 @@ void logger::do_notify_event(uint8_t event_, uint64_t value, event_subscriber_.notify(error::success, event_, value, point); } -void logger::subscribe_events(event_notifier&& handler) NOEXCEPT +void logger::subscribe_events(event_notifier&& handler) const NOEXCEPT { if (stopped()) { @@ -171,7 +172,7 @@ void logger::subscribe_events(event_notifier&& handler) NOEXCEPT } // private -void logger::do_subscribe_events(const event_notifier& handler) NOEXCEPT +void logger::do_subscribe_events(const event_notifier& handler) const NOEXCEPT { BC_ASSERT(stranded()); event_subscriber_.subscribe(move_copy(handler));