@@ -11,11 +11,10 @@ using namespace eth;
11
11
EthGetworkClient::EthGetworkClient (unsigned farmRecheckPeriod, bool submitHashrate) : PoolClient(), Worker(" getwork" ), m_submit_hashrate(submitHashrate)
12
12
{
13
13
m_farmRecheckPeriod = farmRecheckPeriod;
14
- m_authorized = true ;
15
- m_connection_changed = true ;
14
+ m_subscribed. store ( true , std::memory_order_relaxed) ;
15
+ m_authorized. store ( true , std::memory_order_relaxed) ;
16
16
if (m_submit_hashrate)
17
17
m_client_id = h256::random ();
18
- startWorking ();
19
18
}
20
19
21
20
EthGetworkClient::~EthGetworkClient ()
@@ -25,22 +24,25 @@ EthGetworkClient::~EthGetworkClient()
25
24
26
25
void EthGetworkClient::connect ()
27
26
{
28
- if (m_connection_changed) {
29
- stringstream ss;
30
- ss << " http://" + m_conn->Host () << ' :' << m_conn->Port ();
31
- if (m_conn->Path ().length ())
32
- ss << m_conn->Path ();
33
- p_client = new ::JsonrpcGetwork (new jsonrpc::HttpClient (ss.str ()));
27
+ stringstream ss;
28
+ ss << " http://" + m_conn->Host () << ' :' << m_conn->Port ();
29
+ if (m_conn->Path ().length ())
30
+ ss << m_conn->Path ();
31
+ p_client = new ::JsonrpcGetwork (new jsonrpc::HttpClient (ss.str ()));
32
+
33
+ // Since we do not have a real connected state with getwork, we just fake it.
34
+ if (m_onConnected) {
35
+ m_onConnected ();
34
36
}
35
37
36
- m_connection_changed = false ;
37
- m_justConnected = true ; // We set a fake flag, that we can check with workhandler if connection works
38
+ // No need to worry about starting again.
39
+ // Worker class prevents that
40
+ startWorking ();
38
41
}
39
42
40
43
void EthGetworkClient::disconnect ()
41
44
{
42
- m_connected = false ;
43
- m_justConnected = false ;
45
+ m_connected.store (false , std::memory_order_relaxed);
44
46
45
47
// Since we do not have a real connected state with getwork, we just fake it.
46
48
if (m_onDisconnected) {
@@ -59,7 +61,7 @@ void EthGetworkClient::submitHashrate(string const & rate)
59
61
void EthGetworkClient::submitSolution (const Solution& solution)
60
62
{
61
63
// Immediately send found solution without wait for loop
62
- if (m_connected || m_justConnected ) {
64
+ if (m_connected. load (std::memory_order_relaxed) ) {
63
65
try
64
66
{
65
67
bool accepted = p_client->eth_submitWork (" 0x" + toHex (solution.nonce ), " 0x" + toString (solution.work .header ), " 0x" + toString (solution.mixHash ));
@@ -85,9 +87,9 @@ void EthGetworkClient::submitSolution(const Solution& solution)
85
87
// Handles all getwork communication.
86
88
void EthGetworkClient::workLoop ()
87
89
{
88
- while (true )
90
+ while (! shouldStop () )
89
91
{
90
- if (m_connected || m_justConnected ) {
92
+ if (m_connected. load (std::memory_order_relaxed) ) {
91
93
92
94
// Get Work
93
95
try
@@ -98,14 +100,6 @@ void EthGetworkClient::workLoop()
98
100
newWorkPackage.epoch = ethash::find_epoch_number (
99
101
ethash::hash256_from_bytes (h256{v[1 ].asString ()}.data ()));
100
102
101
- // Since we do not have a real connected state with getwork, we just fake it.
102
- // If getting work succeeds we know that the connection works
103
- if (m_justConnected && m_onConnected) {
104
- m_justConnected = false ;
105
- m_connected = true ;
106
- m_onConnected ();
107
- }
108
-
109
103
// Check if header changes so the new workpackage is really new
110
104
if (newWorkPackage.header != m_prevWorkPackage.header ) {
111
105
m_prevWorkPackage.header = newWorkPackage.header ;
@@ -129,16 +123,16 @@ void EthGetworkClient::workLoop()
129
123
{
130
124
p_client->eth_submitHashrate (m_currentHashrateToSubmit, " 0x" + m_client_id.hex ());
131
125
}
132
- catch (const jsonrpc::JsonRpcException&)
126
+ catch (const jsonrpc::JsonRpcException& _e )
133
127
{
134
- // cwarn << "Failed to submit hashrate.";
135
- // cwarn << boost::diagnostic_information(_e);
128
+ cwarn << " Failed to submit hashrate." ;
129
+ cwarn << boost::diagnostic_information (_e);
136
130
}
137
131
m_currentHashrateToSubmit.clear ();
138
132
}
139
133
}
140
134
141
- // Sleep
135
+ // Sleep for --farm-recheck defined period
142
136
this_thread::sleep_for (chrono::milliseconds (m_farmRecheckPeriod));
143
137
}
144
138
}
0 commit comments