...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
(EXPERIMENTAL) A pool of connections of variable size.
Defined in header <boost/mysql/connection_pool.hpp>
class connection_pool
Name |
Description |
---|---|
The executor type associated to this object. |
Name |
Description |
---|---|
Retrieves a connection from the pool. |
|
Runs the pool task in charge of managing connections. |
|
Stops any current outstanding operation and marks the pool as cancelled. |
|
connection_pool [constructor] |
Constructs a connection pool. |
Retrieves the executor associated to this object. |
|
Move assignment. |
|
Returns whether the object is in a moved-from state. |
|
~connection_pool [destructor] |
Destructor. |
A connection pool creates and manages any_connection
objects. Using a
pool allows to reuse sessions, avoiding part of the overhead associated to
session establishment. It also features built-in error handling and reconnection.
See the discussion and examples for more details on when to use this class.
Connections are retrieved by async_get_connection
, which yields
a pooled_connection
object. They are
returned to the pool when the pooled_connection
is destroyed, or by calling pooled_connection::return_without_reset
.
A pool needs to be run before it can return any connection. Use async_run
for this. Pools can only
be run once.
Connections are created, connected and managed internally by the pool, following a well-defined state model. Please refer to the discussion for details.
Due to oddities in Boost.Asio's universal async model, this class only exposes
async functions. You can use asio::use_future
to transform them into sync functions (please read the discussion for details).
This is a move-only type.
By default, connection pools are not thread-safe, but
most functions can be made thread-safe by passing an adequate pool_executor_params
objects to
the constructor. See pool_executor_params::thread_safe
and the discussion for
details.
Distinct objects: safe.
Shared objects: unsafe, unless passing adequate values to the constructor.
Connection pool objects create an internal state object that is referenced
by other objects and operations (like pooled_connection
). This object
will be kept alive using shared ownership semantics even after the connection_pool
object is destroyed. This
results in intuitive lifetime rules.
This part of the API is experimental, and may change in successive releases without previous notice.
Convenience header <boost/mysql.hpp>