4 #include "util/http/https_client_pool.h" 6 #include "base/logging.h" 7 #include "util/http/https_client.h" 13 void HttpsClientPool::HandleGuard::operator()(HttpsClient* client) {
16 CHECK_GT(pool_->existing_handles_, 0);
18 if (client->status()) {
19 VLOG(1) <<
"Deleting client " << client->native_handle() <<
" due to " << client->status();
20 --pool_->existing_handles_;
24 pool_->available_handles_.emplace_back(client);
28 HttpsClientPool::HttpsClientPool(
const std::string& domain, ::boost::asio::ssl::context* ssl_ctx,
30 : ssl_cntx_(*ssl_ctx), io_cntx_(*io_cntx), domain_(domain) {}
32 HttpsClientPool::~HttpsClientPool() {
33 for (
auto* ptr : available_handles_) {
39 while (!available_handles_.empty()) {
41 std::unique_ptr<HttpsClient> ptr{std::move(available_handles_.front())};
43 available_handles_.pop_front();
49 VLOG(1) <<
"Reusing https client " << ptr->native_handle();
52 return ClientHandle(ptr.release(),
HandleGuard{
this});
56 VLOG(1) <<
"Creating a new https client";
58 std::unique_ptr<HttpsClient> client(
new HttpsClient{domain_, &io_cntx_, &ssl_cntx_});
59 client->set_retry_count(retry_cnt_);
61 auto ec = client->Connect(connect_msec_);
63 LOG_IF(WARNING, ec) <<
"HttpsClientPool: Could not connect " << ec;
66 return ClientHandle{client.release(),
HandleGuard{
this}};
ClientHandle GetHandle()
Returns https client connection from the pool.