Browse Source

Merge pull request #23 from ethereum-mining/fix-stratum-thread

Stratum: Reuse service thread on reconnect
cl-refactor
Paweł Bylica 8 years ago
committed by GitHub
parent
commit
0cd4fc4e7d
  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