From 7d3baacbcc64c747374ab8086bf39faeaed9abf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Ja=C5=82ocha?= Date: Tue, 8 Oct 2024 22:46:10 +0200 Subject: [PATCH] Move crypto calculations to asio thread (#4802) * Move crypto calculations to asio thread * Update src/connection.cpp Co-authored-by: Ranieri Althoff <1993083+ranisalt@users.noreply.github.com> --------- Co-authored-by: Ranieri Althoff <1993083+ranisalt@users.noreply.github.com> --- src/connection.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/connection.cpp b/src/connection.cpp index cf6fa26527..349f9ba905 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -277,7 +277,14 @@ void Connection::send(const OutputMessage_ptr& msg) bool noPendingWrite = messageQueue.empty(); messageQueue.emplace_back(msg); if (noPendingWrite) { - internalSend(msg); + try { + boost::asio::post(socket.get_executor(), + [thisPtr = shared_from_this(), msg] { thisPtr->internalSend(msg); }); + } catch (const boost::system::system_error& e) { + std::cout << "[Network error - Connection::send] " << e.what() << std::endl; + messageQueue.clear(); + close(FORCE_CLOSE); + } } }