Skip to content

Commit

Permalink
Support connection lifespan
Browse files Browse the repository at this point in the history
  • Loading branch information
elsid authored and thed636 committed Apr 7, 2020
1 parent e716228 commit 7266a07
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions examples/connection_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion include/ozo/connection_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

/**
Expand Down Expand Up @@ -314,7 +315,7 @@ class connection_pool {
* Thread safe by default (`ozo::thread_safety<true>`).
*/
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)) {}

/**
Expand Down

0 comments on commit 7266a07

Please sign in to comment.