@@ -66,7 +66,8 @@ static const char *states[] = {
66
66
" host-lookup" ,
67
67
" connecting" ,
68
68
" connected" ,
69
- " closing"
69
+ " closing" ,
70
+ " reconnecting"
70
71
};
71
72
#endif
72
73
@@ -173,10 +174,16 @@ void xmrig::Client::tick(uint64_t now)
173
174
else if (m_keepAlive && now > m_keepAlive) {
174
175
ping ();
175
176
}
177
+
178
+ return ;
179
+ }
180
+
181
+ if (m_state == ReconnectingState && m_expire && now > m_expire) {
182
+ return connect ();
176
183
}
177
184
178
- if (m_expire && now > m_expire && m_state == ConnectingState ) {
179
- connect ();
185
+ if (m_state == ConnectingState && m_expire && now > m_expire ) {
186
+ return reconnect ();
180
187
}
181
188
}
182
189
@@ -479,7 +486,6 @@ int xmrig::Client::resolve(const char *host)
479
486
{
480
487
setState (HostLookupState);
481
488
482
- m_expire = 0 ;
483
489
m_recvBufPos = 0 ;
484
490
485
491
if (m_failures == -1 ) {
@@ -815,6 +821,8 @@ void xmrig::Client::parseResponse(int64_t id, const rapidjson::Value &result, co
815
821
void xmrig::Client::ping ()
816
822
{
817
823
send (snprintf (m_sendBuf, sizeof (m_sendBuf), " {\" id\" :%" PRId64 " ,\" jsonrpc\" :\" 2.0\" ,\" method\" :\" keepalived\" ,\" params\" :{\" id\" :\" %s\" }}\n " , m_sequence, m_rpcId.data ()));
824
+
825
+ m_keepAlive = 0 ;
818
826
}
819
827
820
828
@@ -861,7 +869,7 @@ void xmrig::Client::reconnect()
861
869
return m_listener->onClose (this , -1 );
862
870
}
863
871
864
- setState (ConnectingState );
872
+ setState (ReconnectingState );
865
873
866
874
m_failures++;
867
875
m_listener->onClose (this , (int ) m_failures);
@@ -878,6 +886,23 @@ void xmrig::Client::setState(SocketState state)
878
886
return ;
879
887
}
880
888
889
+ switch (state) {
890
+ case HostLookupState:
891
+ m_expire = 0 ;
892
+ break ;
893
+
894
+ case ConnectingState:
895
+ m_expire = uv_now (uv_default_loop ()) + kConnectTimeout ;
896
+ break ;
897
+
898
+ case ReconnectingState:
899
+ m_expire = uv_now (uv_default_loop ()) + m_retryPause;
900
+ break ;
901
+
902
+ default :
903
+ break ;
904
+ }
905
+
881
906
m_state = state;
882
907
}
883
908
0 commit comments