From ef81c2564c7d3553c249299a2430076d585f9ec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Sat, 16 Mar 2024 14:27:53 +0100 Subject: [PATCH] Properly close channel container --- nano/node/transport/tcp.cpp | 9 ++++++++- nano/node/transport/tcp.hpp | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/nano/node/transport/tcp.cpp b/nano/node/transport/tcp.cpp index c8acf552dd..bc86b4cbc0 100644 --- a/nano/node/transport/tcp.cpp +++ b/nano/node/transport/tcp.cpp @@ -150,7 +150,13 @@ void nano::transport::tcp_channels::stop () message_manager.stop (); - // Close all TCP sockets + close (); +} + +void nano::transport::tcp_channels::close () +{ + nano::lock_guard lock{ mutex }; + for (auto const & channel : channels) { if (channel.socket) @@ -163,6 +169,7 @@ void nano::transport::tcp_channels::stop () channel.response_server->stop (); } } + channels.clear (); } diff --git a/nano/node/transport/tcp.hpp b/nano/node/transport/tcp.hpp index a362ac5399..a2da9d5246 100644 --- a/nano/node/transport/tcp.hpp +++ b/nano/node/transport/tcp.hpp @@ -136,6 +136,7 @@ namespace transport void start (); void stop (); + void close (); bool insert (std::shared_ptr const &, std::shared_ptr const &, std::shared_ptr const &); void erase (nano::tcp_endpoint const &); std::size_t size () const;