![]() |
|
|||
Warning, file /include/boost/mysql/pool_params.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 // 0002 // Copyright (c) 2019-2024 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/mysql/detail/access.hpp> 0016 0017 #include <boost/asio/any_io_executor.hpp> 0018 #include <boost/asio/ssl/context.hpp> 0019 #include <boost/asio/strand.hpp> 0020 #include <boost/optional/optional.hpp> 0021 0022 #include <chrono> 0023 #include <cstddef> 0024 #include <string> 0025 0026 namespace boost { 0027 namespace mysql { 0028 0029 /** 0030 * \brief (EXPERIMENTAL) Executor configuration for connection pools. 0031 * \details 0032 * Contains two executors: one for the pool's internal objects, and another for the connections 0033 * created by the pool. 0034 * \n 0035 * You may use \ref thread_safe to create an instance of this class 0036 * that makes pools thread-safe. 0037 * 0038 * \par Experimental 0039 * This part of the API is experimental, and may change in successive 0040 * releases without previous notice. 0041 */ 0042 struct pool_executor_params 0043 { 0044 /// The executor to be used by the pool's internal objects. 0045 asio::any_io_executor pool_executor; 0046 0047 /// The executor to be used by connections created by the pool. 0048 asio::any_io_executor connection_executor; 0049 0050 /** 0051 * \brief Creates a pool_executor_params object that makes pools thread-safe. 0052 * \details 0053 * Creates an `asio::strand` object wrapping `ex` and uses it as the pool 0054 * executor. Uses `ex` directly for the connections. The resulting configuration 0055 * makes safe to call \ref connection_pool::async_get_connection, 0056 * \ref connection_pool::async_run, \ref connection_pool::cancel, 0057 * `~pooled_connection` and \ref pooled_connection::return_without_reset 0058 * concurrently from different threads. 0059 * 0060 * \par Exception safety 0061 * Strong guarantee. Creating the strand may throw. 0062 */ 0063 static pool_executor_params thread_safe(asio::any_io_executor ex) 0064 { 0065 return pool_executor_params{asio::make_strand(ex), ex}; 0066 } 0067 }; 0068 0069 /** 0070 * \brief (EXPERIMENTAL) Configuration parameters for \ref connection_pool. 0071 * \details 0072 * This is an owning type. 0073 * 0074 * \par Experimental 0075 * This part of the API is experimental, and may change in successive 0076 * releases without previous notice. 0077 */ 0078 struct pool_params 0079 { 0080 /** 0081 * \brief Determines how to establish a physical connection to the MySQL server. 0082 * \details 0083 * Connections created by the pool will use this address to connect to the 0084 * server. This can be either a host and port or a UNIX socket path. 0085 * Defaults to (localhost, 3306). 0086 */ 0087 any_address server_address; 0088 0089 /// User name that connections created by the pool should use to authenticate as. 0090 std::string username; 0091 0092 /// Password that connections created by the pool should use. 0093 std::string password; 0094 0095 /** 0096 * \brief Database name that connections created by the pool will use when connecting. 0097 * \details Leave it empty to select no database (this is the default). 0098 */ 0099 std::string database; 0100 0101 /** 0102 * \brief Controls whether connections created by the pool will use TLS or not. 0103 * \details 0104 * See \ref ssl_mode for more information about the possible modes. 0105 * This option is only relevant when `server_address.type() == address_type::host_and_port`. 0106 * UNIX socket connections will never use TLS, regardless of this value. 0107 */ 0108 ssl_mode ssl{ssl_mode::enable}; 0109 0110 /** 0111 * \brief Whether to enable support for semicolon-separated text queries for connections created by the 0112 * pool. \details Disabled by default. 0113 */ 0114 bool multi_queries{false}; 0115 0116 /// Initial size (in bytes) of the internal buffer for the connections created by the pool. 0117 std::size_t initial_buffer_size{default_initial_read_buffer_size}; 0118 0119 /** 0120 * \brief Initial number of connections to create. 0121 * \details 0122 * When \ref connection_pool::async_run starts running, this number of connections 0123 * will be created and connected. 0124 */ 0125 std::size_t initial_size{1}; 0126 0127 /** 0128 * \brief Max number of connections to create. 0129 * \details 0130 * When a connection is requested, but all connections are in use, new connections 0131 * will be created and connected up to this size. 0132 * \n 0133 * Defaults to the maximum number of concurrent connections that MySQL 0134 * servers allow by default. If you increase this value, increase the server's 0135 * max number of connections, too (by setting the `max_connections` global variable). 0136 * \n 0137 * This value must be `> 0` and `>= initial_size`. 0138 */ 0139 std::size_t max_size{151}; 0140 0141 /** 0142 * \brief The SSL context to use for connections using TLS. 0143 * \details 0144 * If a non-empty value is provided, all connections created by the pool 0145 * will use the passed context when using TLS. This allows setting TLS options 0146 * to pool-created connections. 0147 * \n 0148 * If an empty value is passed (the default) and the connections require TLS, 0149 * an internal SSL context with suitable options will be created by the pool. 0150 */ 0151 boost::optional<asio::ssl::context> ssl_ctx{}; 0152 0153 /** 0154 * \brief The timeout to use when connecting. 0155 * \details 0156 * Connections will be connected by the pool before being handed to the user 0157 * (using \ref any_connection::async_connect). 0158 * If the operation takes longer than this timeout, 0159 * the operation will be interrupted, considered as failed and retried later. 0160 * \n 0161 * Set this timeout to zero to disable it. 0162 * \n 0163 * This value must not be negative. 0164 */ 0165 std::chrono::steady_clock::duration connect_timeout{std::chrono::seconds(20)}; 0166 0167 /** 0168 * \brief The interval between connect attempts. 0169 * \details 0170 * When session establishment fails, the operation will be retried until 0171 * success. This value determines the interval between consecutive connection 0172 * attempts. 0173 * \n 0174 * This value must be greater than zero. 0175 */ 0176 std::chrono::steady_clock::duration retry_interval{std::chrono::seconds(30)}; 0177 0178 /** 0179 * \brief The health-check interval. 0180 * \details 0181 * If a connection becomes idle and hasn't been handed to the user for 0182 * `ping_interval`, a health-check will be performed (using \ref any_connection::async_ping). 0183 * Pings will be sent with a periodicity of `ping_interval` until the connection 0184 * is handed to the user, or a ping fails. 0185 * \n 0186 * Set this interval to zero to disable pings. 0187 * \n 0188 * This value must not be negative. 0189 */ 0190 std::chrono::steady_clock::duration ping_interval{std::chrono::hours(1)}; 0191 0192 /** 0193 * \brief The timeout to use for pings and session resets. 0194 * \details 0195 * If pings (as per \ref any_connection::async_ping) or session resets 0196 * (as per \ref any_connection::async_reset_connection) take longer than this 0197 * timeout, they will be cancelled, and the operation will be considered failed. 0198 * \n 0199 * Set this timeout to zero to disable it. 0200 * \n 0201 * This value must not be negative. 0202 */ 0203 std::chrono::steady_clock::duration ping_timeout{std::chrono::seconds(10)}; 0204 }; 0205 0206 } // namespace mysql 0207 } // namespace boost 0208 0209 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |