diff --git a/nano/node/transport/tcp_channel.cpp b/nano/node/transport/tcp_channel.cpp index 0d1f157be0..3cf1297018 100644 --- a/nano/node/transport/tcp_channel.cpp +++ b/nano/node/transport/tcp_channel.cpp @@ -25,7 +25,7 @@ nano::transport::tcp_channel::tcp_channel (nano::node & node_a, std::shared_ptr< nano::transport::tcp_channel::~tcp_channel () { close (); - debug_assert (!sending_task.joinable ()); + release_assert (!sending_task.joinable ()); } void nano::transport::tcp_channel::close () @@ -37,20 +37,26 @@ void nano::transport::tcp_channel::close () void nano::transport::tcp_channel::start () { - sending_task = nano::async::task (strand, [this] (nano::async::condition & condition) -> asio::awaitable { - try - { - co_await run_sending (condition); - } - catch (boost::system::system_error const & ex) - { - // Operation aborted is expected when cancelling the acceptor - debug_assert (ex.code () == asio::error::operation_aborted); - } - debug_assert (strand.running_in_this_thread ()); + sending_task = nano::async::task (strand, [this] (nano::async::condition & condition) { + return start_sending (condition); // This is not a coroutine, but a corotuine factory }); } +asio::awaitable nano::transport::tcp_channel::start_sending (nano::async::condition & condition) +{ + debug_assert (strand.running_in_this_thread ()); + try + { + co_await run_sending (condition); + } + catch (boost::system::system_error const & ex) + { + // Operation aborted is expected when cancelling the acceptor + debug_assert (ex.code () == asio::error::operation_aborted); + } + debug_assert (strand.running_in_this_thread ()); +} + void nano::transport::tcp_channel::stop () { if (sending_task.joinable ()) diff --git a/nano/node/transport/tcp_channel.hpp b/nano/node/transport/tcp_channel.hpp index 0de1698e0b..f76634b672 100644 --- a/nano/node/transport/tcp_channel.hpp +++ b/nano/node/transport/tcp_channel.hpp @@ -71,6 +71,7 @@ class tcp_channel final : public nano::transport::channel, public std::enable_sh void start (); void stop (); + asio::awaitable start_sending (nano::async::condition &); asio::awaitable run_sending (nano::async::condition &); asio::awaitable send_one (traffic_type, tcp_channel_queue::entry_t const &);