diff --git a/contrib/resource_pool b/contrib/resource_pool index a246797a2..6a4074465 160000 --- a/contrib/resource_pool +++ b/contrib/resource_pool @@ -1 +1 @@ -Subproject commit a246797a2d8ebddbd7a56d07775a9d134127dd96 +Subproject commit 6a4074465cc672fc1999035ef3e851d7c250134c diff --git a/examples/connection_pool.cpp b/examples/connection_pool.cpp index 3b7bf9c7f..4a01879a4 100644 --- a/examples/connection_pool.cpp +++ b/examples/connection_pool.cpp @@ -34,6 +34,8 @@ int main(int argc, char **argv) { connection_pool_config.queue_capacity = 10; // Maximum time duration to store unused open connection connection_pool_config.idle_timeout = std::chrono::seconds(60); + // Maximum time duration to keep connection open + connection_pool_config.lifespan = std::chrono::hours(24); // Creating connection pool from connection_info as the underlying ConnectionSource ozo::connection_pool connection_pool(connection_info, connection_pool_config); diff --git a/include/ozo/connection_pool.h b/include/ozo/connection_pool.h index f93f2aadb..ea0d65950 100644 --- a/include/ozo/connection_pool.h +++ b/include/ozo/connection_pool.h @@ -21,6 +21,7 @@ struct connection_pool_config { std::size_t capacity = 10; //!< maximum number of stored connections std::size_t queue_capacity = 128; //!< maximum number of queued requests to get available connection time_traits::duration idle_timeout = std::chrono::seconds(60); //!< time interval to close connection after last usage + time_traits::duration lifespan = std::chrono::hours(24); //!< time interval to keep connection open }; /** @@ -314,7 +315,7 @@ class connection_pool { * Thread safe by default (`ozo::thread_safety`). */ connection_pool(Source source, const connection_pool_config& config, const ThreadSafety& /*thread_safety*/ = ThreadSafety{}) - : impl_(config.capacity, config.queue_capacity, config.idle_timeout), + : impl_(config.capacity, config.queue_capacity, config.idle_timeout, config.lifespan), source_(std::move(source)) {} /**