Browse Source

busy

cl-refactor
Genoil 9 years ago
parent
commit
8b8ac86ece
  1. 21
      libstratum/EthStratumClient.cpp
  2. 7
      libstratum/EthStratumClient.h

21
libstratum/EthStratumClient.cpp

@ -22,6 +22,7 @@ EthStratumClient::EthStratumClient(GenericFarm<EthashProofOfWork> * f, MinerType
m_maxRetries = retries; m_maxRetries = retries;
p_farm = f; p_farm = f;
p_worktimer = nullptr;
connect(); connect();
} }
@ -74,7 +75,10 @@ void EthStratumClient::reconnect()
m_socket.close(); m_socket.close();
m_authorized = false; m_authorized = false;
m_connected = false; m_connected = false;
if (p_worktimer) {
p_worktimer->cancel();
p_worktimer = nullptr;
}
if (!m_failover.host.empty()) if (!m_failover.host.empty())
{ {
m_retries++; m_retries++;
@ -306,10 +310,15 @@ void EthStratumClient::processReponse(Json::Value& responseObject)
EthashAux::computeFull(sha3(seedHash), true); EthashAux::computeFull(sha3(seedHash), true);
if (headerHash != m_current.headerHash) if (headerHash != m_current.headerHash)
{ {
if (p_worktimer)
p_worktimer->cancel();
m_current.headerHash = h256(sHeaderHash); m_current.headerHash = h256(sHeaderHash);
m_current.seedHash = seedHash; m_current.seedHash = seedHash;
m_current.boundary = h256(sShareTarget);// , h256::AlignRight); m_current.boundary = h256(sShareTarget);// , h256::AlignRight);
p_farm->setWork(m_current); p_farm->setWork(m_current);
p_worktimer = new boost::asio::deadline_timer(m_io_service, boost::posix_time::seconds(m_worktimeout));
p_worktimer->async_wait(boost::bind(&EthStratumClient::work_timeout_handler, this, boost::asio::placeholders::error));
} }
} }
} }
@ -330,6 +339,16 @@ void EthStratumClient::processReponse(Json::Value& responseObject)
} }
void EthStratumClient::work_timeout_handler(const boost::system::error_code& ec) {
if (!ec) {
cnote << "No new work received in" << m_worktimeout << "seconds. Reconnecting...";
// keep this thread alive until reconnection.
p_worktimer = new boost::asio::deadline_timer(m_io_service, boost::posix_time::seconds(m_worktimeout));
p_worktimer->async_wait(boost::bind(&EthStratumClient::work_timeout_handler, this, boost::asio::placeholders::error));
reconnect();
}
}
bool EthStratumClient::submit(EthashProofOfWork::Solution solution) { bool EthStratumClient::submit(EthashProofOfWork::Solution solution) {
cnote << "Solution found; Submitting to" << p_active->host << "..."; cnote << "Solution found; Submitting to" << p_active->host << "...";

7
libstratum/EthStratumClient.h

@ -44,7 +44,8 @@ private:
void disconnect(); void disconnect();
void resolve_handler(const boost::system::error_code& ec, tcp::resolver::iterator i); void resolve_handler(const boost::system::error_code& ec, tcp::resolver::iterator i);
void connect_handler(const boost::system::error_code& ec, tcp::resolver::iterator i); void connect_handler(const boost::system::error_code& ec, tcp::resolver::iterator i);
void work_timeout_handler(const boost::system::error_code& ec);
void readline(); void readline();
void handleResponse(const boost::system::error_code& ec); void handleResponse(const boost::system::error_code& ec);
void readResponse(const boost::system::error_code& ec, std::size_t bytes_transferred); void readResponse(const boost::system::error_code& ec, std::size_t bytes_transferred);
@ -63,6 +64,7 @@ private:
int m_retries = 0; int m_retries = 0;
int m_maxRetries; int m_maxRetries;
int m_worktimeout = 10;
boost::mutex m_mtx; boost::mutex m_mtx;
int m_pending; int m_pending;
@ -78,4 +80,7 @@ private:
boost::asio::streambuf m_requestBuffer; boost::asio::streambuf m_requestBuffer;
boost::asio::streambuf m_responseBuffer; boost::asio::streambuf m_responseBuffer;
boost::asio::deadline_timer * p_worktimer;
}; };
Loading…
Cancel
Save