Browse Source

Stratum: Reuse service thread on reconnect

cl-refactor
Paweł Bylica 8 years ago
parent
commit
1131ffebaf
No known key found for this signature in database GPG Key ID: 7A0C037434FE77EF
  1. 13
      libstratum/EthStratumClient.cpp

13
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();

Loading…
Cancel
Save