Skip to content

Commit

Permalink
[coro_io] add size() for channel/client_pool
Browse files Browse the repository at this point in the history
  • Loading branch information
poor-circle committed Feb 28, 2024
1 parent d28cd67 commit 8ce23f7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/ylt/coro_io/channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ class channel {
return ch;
}

/**
* @brief return the channel's hosts size.
*
* @return std::size_t
*/
std::size_t size() const noexcept { return client_pools_.size(); }

private:
void init(const std::vector<std::string_view>& hosts,
const channel_config& config, const std::vector<int>& weights,
Expand Down
12 changes: 12 additions & 0 deletions include/ylt/coro_io/client_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,22 @@ class client_pool : public std::enable_shared_from_this<
return send_request(std::move(op), pool_config_.client_config);
}

/**
* @brief approx connection of client pools
*
* @return std::size_t
*/
std::size_t free_client_count() const noexcept {
return free_clients_.size() + short_connect_clients_.size();
}

/**
* @brief approx connection of client pools
*
* @return std::size_t
*/
std::size_t size() const noexcept { return free_client_count(); }

std::string_view get_host_name() const noexcept { return host_name_; }

private:
Expand Down

0 comments on commit 8ce23f7

Please sign in to comment.