35#ifndef A11_NET_HTTP_CONNECTION_POOL_H_
36#define A11_NET_HTTP_CONNECTION_POOL_H_
42#include <absl/container/flat_hash_map.h>
43#include <absl/status/statusor.h>
48#include "thread/boost_primitives.h"
52class HttpConnectionPool;
72 [[nodiscard]]
const std::shared_ptr<Http2Client>&
client()
const {
77 [[nodiscard]]
bool reused()
const {
return reused_; }
93 std::shared_ptr<Http2Client> client_;
106 :
public std::enable_shared_from_this<HttpConnectionPool> {
109 static std::shared_ptr<HttpConnectionPool>
Create();
117 static const std::shared_ptr<HttpConnectionPool>&
Shared();
153 [[nodiscard]]
size_t size()
const;
159 std::weak_ptr<Http2Client> client;
161 std::shared_ptr<a11::Promise<std::shared_ptr<Http2Client>>> dialling;
167 static std::string KeyFor(
const ParsedUrl& origin,
171 void Forget(
const std::string&
key);
174 std::shared_ptr<Http2Client> Adopt(std::string
key,
175 std::shared_ptr<Http2Client> client);
177 mutable thread::Mutex mu_;
178 absl::flat_hash_map<std::string, Entry> entries_ ABSL_GUARDED_BY(mu_);
Shared handle to one asynchronous result.
Definition future.h:126
A borrowed connection, held for as long as a caller needs it.
Definition connection_pool.h:67
bool multiplexed() const
Definition connection_pool.cc:73
const std::shared_ptr< Http2Client > & client() const
Definition connection_pool.h:72
bool reused() const
Definition connection_pool.h:77
HttpConnectionLease()=default
void Release()
Releases this share of the connection early; the destructor does it too.
Definition connection_pool.h:85
Hands out connections to origins, sharing them while they are in use.
Definition connection_pool.h:106
size_t size() const
Definition connection_pool.cc:144
a11::Future< HttpConnectionLease > Acquire(const ParsedUrl &origin, Http2Options options)
Borrows a connection to origin, dialling one if needed.
Definition connection_pool.cc:156
static std::shared_ptr< HttpConnectionPool > Create()
Creates an independent pool.
Definition connection_pool.cc:77
static const std::shared_ptr< HttpConnectionPool > & Shared()
The process-wide pool.
Definition connection_pool.cc:83
static a11::Future< HttpConnectionLease > AcquireUnshared(const ParsedUrl &origin, Http2Options options)
Dials a connection nobody else will be given, and leases it.
Definition connection_pool.cc:127
std::string key
Definition discover.cc:782
Completion values used by every asynchronous A11 operation.
A11's nghttp2 HTTP/2 client, server, and streaming primitives.
Body-size limits, buffering thresholds, deadline, TLS, and HTTP protocol negotiation for an HTTP clie...
Definition http2.h:150
An absolute URL split into the parts a connection needs.
Definition url.h:50
Parsing and resolution for the URLs the HTTP and WebSocket transports dial.