@@ -37,14 +37,14 @@ namespace fc::api::rpc {
3737 return connect (ip, port, target, token);
3838 }
3939
40- outcome::result<void > Client::connect (const std::string &host,
41- const std::string &port,
42- const std::string &target,
43- const std::string &token) {
40+ outcome::result<void > Client::connect (const std::string &host,
41+ const std::string &port,
42+ const std::string &target,
43+ const std::string &token) {
4444 boost::system::error_code ec;
4545 socket->next_layer ().connect ({boost::asio::ip::make_address (host),
46- boost::lexical_cast<uint16_t >(port)},
47- ec);
46+ boost::lexical_cast<uint16_t >(port)},
47+ ec);
4848 if (ec) {
4949 return ec;
5050 }
@@ -92,19 +92,19 @@ namespace fc::api::rpc {
9292 }
9393
9494 void Client::_flush () {
95- if (!writing && !write_queue.empty () && not reconnecting){
95+ if (!writing && !write_queue.empty () && not reconnecting) {
9696 auto &[id, buffer] = write_queue.front ();
9797 writing = true ;
9898 socket->async_write (boost::asio::buffer (buffer.data (), buffer.size ()),
99- [=](auto &&ec, auto ) {
100- std::lock_guard lock{mutex};
101- if (ec) {
102- return _error (ec);
103- }
104- writing = false ;
105- write_queue.pop ();
106- _flush ();
107- });
99+ [=](auto &&ec, auto ) {
100+ std::lock_guard lock{mutex};
101+ if (ec) {
102+ return _error (ec);
103+ }
104+ writing = false ;
105+ write_queue.pop ();
106+ _flush ();
107+ });
108108 }
109109 }
110110
@@ -189,23 +189,34 @@ namespace fc::api::rpc {
189189 }
190190
191191 void Client::reconnect (int counter, std::chrono::milliseconds wait) {
192- if (reconnecting) return ;
192+ if (reconnecting) return ;
193193 reconnecting = true ;
194- logger_->info (" Starting reconnect to {}:{}" , client_data.host , client_data.port );
195- for (int i = 0 ; i < counter; i++){
194+ bool rec_status{false };
195+ logger_->info (
196+ " Starting reconnect to {}:{}" , client_data.host , client_data.port );
197+ for (int i = 0 ; i < counter; i++) {
196198 std::this_thread::sleep_for (wait);
197199 socket.reset ();
198200 socket.emplace (io);
199201 auto res = connect (client_data.host ,
200202 client_data.port ,
201203 client_data.target ,
202204 client_data.token );
203- if (!res.has_error ()) {
205+ if (not res.has_error ()) {
206+ rec_status = true ;
204207 break ;
205208 }
206209 }
207210 reconnecting = false ;
208- logger_->info (" Reconnect to {}:{} was successful" , client_data.host , client_data.port );
209- _flush ();
211+ if (rec_status) {
212+ logger_->info (" Reconnect to {}:{} was successful" ,
213+ client_data.host ,
214+ client_data.port );
215+ _flush ();
216+ } else {
217+ logger_->error (" Reconnect to {}:{} have been failed" ,
218+ client_data.host ,
219+ client_data.port );
220+ }
210221 }
211222} // namespace fc::api::rpc
0 commit comments