Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 08:52:48

0001 //
0002 // Copyright (c) 2019-2025 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 
0008 #ifndef BOOST_MYSQL_POOL_PARAMS_HPP
0009 #define BOOST_MYSQL_POOL_PARAMS_HPP
0010 
0011 #include <boost/mysql/any_address.hpp>
0012 #include <boost/mysql/defaults.hpp>
0013 #include <boost/mysql/ssl_mode.hpp>
0014 
0015 #include <boost/asio/any_io_executor.hpp>
0016 #include <boost/asio/ssl/context.hpp>
0017 #include <boost/optional/optional.hpp>
0018 
0019 #include <chrono>
0020 #include <cstddef>
0021 #include <string>
0022 
0023 namespace boost {
0024 namespace mysql {
0025 
0026 /**
0027  * \brief Configuration parameters for \ref connection_pool.
0028  * \details
0029  * This is an owning type.
0030  */
0031 struct pool_params
0032 {
0033     /**
0034      * \brief Determines how to establish a physical connection to the MySQL server.
0035      * \details
0036      * Connections created by the pool will use this address to connect to the
0037      * server. This can be either a host and port or a UNIX socket path.
0038      * Defaults to (localhost, 3306).
0039      */
0040     any_address server_address;
0041 
0042     /// User name that connections created by the pool should use to authenticate as.
0043     std::string username;
0044 
0045     /// Password that connections created by the pool should use.
0046     std::string password;
0047 
0048     /**
0049      * \brief Database name that connections created by the pool will use when connecting.
0050      * \details Leave it empty to select no database (this is the default).
0051      */
0052     std::string database;
0053 
0054     /**
0055      * \brief Controls whether connections created by the pool will use TLS or not.
0056      * \details
0057      * See \ref ssl_mode for more information about the possible modes.
0058      * This option is only relevant when `server_address.type() == address_type::host_and_port`.
0059      * UNIX socket connections will never use TLS, regardless of this value.
0060      */
0061     ssl_mode ssl{ssl_mode::enable};
0062 
0063     /**
0064      * \brief Whether to enable support for semicolon-separated text queries for connections created by the
0065      * pool. \details Disabled by default.
0066      */
0067     bool multi_queries{false};
0068 
0069     /// Initial size (in bytes) of the internal buffer for the connections created by the pool.
0070     std::size_t initial_buffer_size{default_initial_read_buffer_size};
0071 
0072     /**
0073      * \brief Initial number of connections to create.
0074      * \details
0075      * When \ref connection_pool::async_run starts running, this number of connections
0076      * will be created and connected.
0077      */
0078     std::size_t initial_size{1};
0079 
0080     /**
0081      * \brief Max number of connections to create.
0082      * \details
0083      * When a connection is requested, but all connections are in use, new connections
0084      * will be created and connected up to this size.
0085      * \n
0086      * Defaults to the maximum number of concurrent connections that MySQL
0087      * servers allow by default. If you increase this value, increase the server's
0088      * max number of connections, too (by setting the `max_connections` global variable).
0089      * \n
0090      * This value must be `> 0` and `>= initial_size`.
0091      */
0092     std::size_t max_size{151};
0093 
0094     /**
0095      * \brief The SSL context to use for connections using TLS.
0096      * \details
0097      * If a non-empty value is provided, all connections created by the pool
0098      * will use the passed context when using TLS. This allows setting TLS options
0099      * to pool-created connections.
0100      * \n
0101      * If an empty value is passed (the default) and the connections require TLS,
0102      * an internal SSL context with suitable options will be created by the pool.
0103      */
0104     boost::optional<asio::ssl::context> ssl_ctx{};
0105 
0106     /**
0107      * \brief The timeout to use when connecting.
0108      * \details
0109      * Connections will be connected by the pool before being handed to the user
0110      * (using \ref any_connection::async_connect).
0111      * If the operation takes longer than this timeout,
0112      * the operation will be interrupted, considered as failed and retried later.
0113      * \n
0114      * Set this timeout to zero to disable it.
0115      * \n
0116      * This value must not be negative.
0117      */
0118     std::chrono::steady_clock::duration connect_timeout{std::chrono::seconds(20)};
0119 
0120     /**
0121      * \brief The interval between connect attempts.
0122      * \details
0123      * When session establishment fails, the operation will be retried until
0124      * success. This value determines the interval between consecutive connection
0125      * attempts.
0126      * \n
0127      * This value must be greater than zero.
0128      */
0129     std::chrono::steady_clock::duration retry_interval{std::chrono::seconds(30)};
0130 
0131     /**
0132      * \brief The health-check interval.
0133      * \details
0134      * If a connection becomes idle and hasn't been handed to the user for
0135      * `ping_interval`, a health-check will be performed (using \ref any_connection::async_ping).
0136      * Pings will be sent with a periodicity of `ping_interval` until the connection
0137      * is handed to the user, or a ping fails.
0138      *
0139      * Set this interval to zero to disable pings.
0140      *
0141      * This value must not be negative. It should be smaller than the server's
0142      * idle timeout (as determined by the
0143      * <a
0144      * href="https://dev.mysql.com/doc/refman/8.4/en/server-system-variables.html#sysvar_wait_timeout">wait_timeout</a>
0145      * session variable). Otherwise, the server might close connections
0146      * without the pool detecting it.
0147      */
0148     std::chrono::steady_clock::duration ping_interval{std::chrono::hours(1)};
0149 
0150     /**
0151      * \brief The timeout to use for pings and session resets.
0152      * \details
0153      * If pings (as per \ref any_connection::async_ping) or session resets
0154      * (as per \ref any_connection::async_reset_connection) take longer than this
0155      * timeout, they will be cancelled, and the operation will be considered failed.
0156      * \n
0157      * Set this timeout to zero to disable it.
0158      * \n
0159      * This value must not be negative.
0160      */
0161     std::chrono::steady_clock::duration ping_timeout{std::chrono::seconds(10)};
0162 
0163     /**
0164      * \brief Enables or disables thread-safety.
0165      * \details
0166      * When set to `true`, the resulting connection pool are able to
0167      * be shared between threads at the cost of some performance.
0168      *
0169      * Enabling thread safety for a pool creates an internal `asio::strand` object
0170      * wrapping the executor passed to the pool's constructor.
0171      * All state-mutating functions (including \ref connection_pool::async_run,
0172      * \ref connection_pool::async_get_connection and returning connections)
0173      * will be run through the created strand.
0174      *
0175      * Thread-safety doesn't extend to individual connections: \ref pooled_connection
0176      * objects can't be shared between threads. Thread-safety does not protect
0177      * objects that don't belong to the pool. For instance, `asio::cancel_after`
0178      * creates a timer that must be protected with a strand.
0179      * Refer to
0180      * <a href="../../connection_pool.html#mysql.connection_pool.thread_safe">this
0181      * page</a> for more info.
0182      */
0183     bool thread_safe{false};
0184 
0185     /**
0186      * \brief The executor to be used by individual connections created by the pool.
0187      * \details
0188      * If this member is set to a non-empty value
0189      * (that is, `static_cast<bool>(connection_executor) == true`),
0190      * individual connections will be created using this executor.
0191      * Otherwise, connections will use the pool's executor
0192      * (as per \ref connection_pool::get_executor).
0193      */
0194     asio::any_io_executor connection_executor{};
0195 };
0196 
0197 }  // namespace mysql
0198 }  // namespace boost
0199 
0200 #endif