From 1131ffebafa1b9ce6696ee4adfb5628ad44d57b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 15 May 2017 20:04:51 +0200 Subject: [PATCH] Stratum: Reuse service thread on reconnect --- libstratum/EthStratumClient.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libstratum/EthStratumClient.cpp b/libstratum/EthStratumClient.cpp index be692986d..e73863e36 100644 --- a/libstratum/EthStratumClient.cpp +++ b/libstratum/EthStratumClient.cpp @@ -82,7 +82,16 @@ void EthStratumClient::connect() cnote << "Connecting to stratum server " << p_active->host + ":" + p_active->port; - m_serviceThread = std::thread{boost::bind(&boost::asio::io_service::run, &m_io_service)}; + if (m_serviceThread.joinable()) + { + // If the service thread have been created try to reset the service. + m_io_service.reset(); + } + else + { + // Otherwise, if the first time here, create new thread. + m_serviceThread = std::thread{boost::bind(&boost::asio::io_service::run, &m_io_service)}; + } } #define BOOST_ASIO_ENABLE_CANCELIO @@ -121,7 +130,7 @@ void EthStratumClient::reconnect() } cnote << "Reconnecting in 3 seconds..."; - boost::asio::deadline_timer timer(m_io_service, boost::posix_time::seconds(3)); + boost::asio::deadline_timer timer(m_io_service, boost::posix_time::seconds(3)); timer.wait(); connect();