Skip to content

Commit

Permalink
[coro_io][feat] reconnect wait time now include connect cost time.
Browse files Browse the repository at this point in the history
  • Loading branch information
poor-circle committed Jul 27, 2023
1 parent 503555a commit b608558
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion include/ylt/coro_io/client_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,15 @@ class client_pool : public std::enable_shared_from_this<

async_simple::coro::Lazy<std::unique_ptr<client_t>> reconnect(
std::unique_ptr<client_t> client) {
auto pre_time_point = std::chrono::steady_clock::now();
bool ok = client_t::is_ok(co_await client->reconnect(host_name_));
for (int i = 0; !ok && i < pool_config_.connect_retry_count; ++i) {
co_await coro_io::sleep_for(pool_config_.reconnect_wait_time);
auto post_time_point = std::chrono::steady_clock::now();
auto wait_time =
pool_config_.reconnect_wait_time - (post_time_point - pre_time_point);
if (wait_time > std::chrono::milliseconds{10})
co_await coro_io::sleep_for(wait_time);
pre_time_point = post_time_point;
ok = (client_t::is_ok(co_await client->reconnect(host_name_)));
}
co_return ok ? std::move(client) : nullptr;
Expand Down

0 comments on commit b608558

Please sign in to comment.