summaryrefslogtreecommitdiffstats
path: root/src/lib/pgsql/pgsql_connection.h
diff options
context:
space:
mode:
authorRazvan Becheriu <razvan@isc.org>2021-03-17 15:28:01 +0100
committerRazvan Becheriu <razvan@isc.org>2021-03-29 20:10:52 +0200
commitb92b67c53cfbb472d417567a23d77018d7122747 (patch)
tree7920ea9a0b9e7e5bbfbae28c7c1cdc10336d4b94 /src/lib/pgsql/pgsql_connection.h
parent[#1621] fixed disable network state for connections (diff)
downloadkea-b92b67c53cfbb472d417567a23d77018d7122747.tar.xz
kea-b92b67c53cfbb472d417567a23d77018d7122747.zip
[#1621] add lazy retrieval for connection IOService
Diffstat (limited to 'src/lib/pgsql/pgsql_connection.h')
-rw-r--r--src/lib/pgsql/pgsql_connection.h16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/lib/pgsql/pgsql_connection.h b/src/lib/pgsql/pgsql_connection.h
index 84f6562bcf..da69a7a99b 100644
--- a/src/lib/pgsql/pgsql_connection.h
+++ b/src/lib/pgsql/pgsql_connection.h
@@ -307,13 +307,14 @@ public:
/// Initialize PgSqlConnection object with parameters needed for connection.
///
/// @param parameters Specify the connection details.
- /// @param io_service The IOService object, used for all ASIO operations.
+ /// @param io_access_callback The IOService access callback.
/// @param callback The connection recovery callback.
PgSqlConnection(const ParameterMap& parameters,
- const isc::asiolink::IOServicePtr& io_service = isc::asiolink::IOServicePtr(),
+ IOServiceAccessCallbackPtr io_access_callback = IOServiceAccessCallbackPtr(),
DbCallback callback = DbCallback())
- : DatabaseConnection(parameters), io_service_(io_service),
- callback_(callback) {
+ : DatabaseConnection(parameters),
+ io_service_access_callback_(io_access_callback),
+ io_service_(), callback_(callback) {
}
/// @brief Destructor
@@ -425,6 +426,9 @@ public:
///
/// @note The recover function must be run on the IO Service thread.
void startRecoverDbConnection() {
+ if (!io_service_ && io_service_access_callback_) {
+ io_service_ = (*io_service_access_callback_)();
+ }
if (callback_ && io_service_) {
io_service_->post(std::bind(callback_, reconnectCtl()));
}
@@ -451,6 +455,10 @@ public:
return (conn_);
}
+ /// @brief Callback which returns the IOService that can be used to recover
+ /// the connection.
+ IOServiceAccessCallbackPtr io_service_access_callback_;
+
/// @brief IOService object, used for all ASIO operations.
isc::asiolink::IOServicePtr io_service_;