OZO 「お象」
Boost.Asio and libpq based asynchronous PostgreSQL unofficial header-only C++17 client library.
ozo::pooled_connection< Rep, Executor > Class Template Reference

#include <ozo/connection_pool.h>

Description

template<typename Rep, typename Executor = asio::io_context::executor_type>
class ozo::pooled_connection< Rep, Executor >

Pool bound model for Connection concept.

Connection concept model which is bound to and may be obtained only from the connection pool. On the pooled_connection object destruction, the underlying handle that contains a connection will be returned to the handle-associated connection pool. If the connection is in a bad state either its current transaction status is different than ozo::transaction_status::idle then it will not return to the pool and be closed. The class object is non-copyable.

Template Parameters
Rep— underlying connection pool representation for the real connection.
Executor— the type of the executor is used to perform IO; currently only boost::asio::io_context::executor_type is supported.
Thread safety
Distinct objects: Safe
Shared objects: Unsafe
Models
Connection

Types

using rep_type = Rep
 Connection representation type.
 
using native_handle_type = typename connection_traits< rep_type >::native_handle_type
 Native connection handle type.
 
using oid_map_type = typename connection_traits< rep_type >::oid_map_type
 Oid map of types that are used with the connection.
 
using error_context_type = typename connection_traits< rep_type >::error_context_type
 Additional error context which could provide context depended information for errors.
 
using statistics_type = typename connection_traits< rep_type >::statistics_type
 Connection statistics to be collected.
 
using executor_type = Executor
 The type of the executor associated with the object.
 

Public Member Functions

native_handle_type native_handle () const noexcept
 
const oid_map_typeoid_map () const noexcept
 
const error_context_typeget_error_context () const noexcept
 
void set_error_context (error_context_type v={})
 
executor_type get_executor () const noexcept
 
template<typename WaitHandler >
void async_wait_write (WaitHandler &&handler)
 
template<typename WaitHandler >
void async_wait_read (WaitHandler &&handler)
 
error_code close () noexcept
 
void cancel () noexcept
 
bool is_bad () const noexcept
 
 operator bool () const noexcept
 
bool is_open () const noexcept
 

Member Function Documentation

◆ async_wait_read()

template<typename Rep , typename Executor >
template<typename WaitHandler >
void ozo::pooled_connection< Rep, Executor >::async_wait_read ( WaitHandler &&  handler)

Asynchronously wait for the connection socket to become ready to read or to have pending error conditions.

Typically this function is used by the library within the connection establishing process and operation execution. Users should not use it directly other than for custom libpq-based opeartions.

Warning
The function is designated to the library operations use only. Do not call this function directly.
Parameters
handler— wait handler with void(ozo::error_code, int=0) signature.

◆ async_wait_write()

template<typename Rep , typename Executor >
template<typename WaitHandler >
void ozo::pooled_connection< Rep, Executor >::async_wait_write ( WaitHandler &&  handler)

Asynchronously wait for the connection socket to become ready to write or to have pending error conditions.

Typically this function is used by the library within the connection establishing process and operation execution. Users should not use it directly other than for custom libpq-based opeartions.

Warning
The function is designated to the library operations use only. Do not call this function directly.
Parameters
handler— wait handler with void(ozo::error_code, int=0) signature.

◆ cancel()

template<typename Rep , typename Executor >
void ozo::pooled_connection< Rep, Executor >::cancel
noexcept

Cancel all asynchronous operations associated with the connection.

This function causes all outstanding asynchronous operations to finish immediately, and the handlers for cancelled operations will be passed the boost::asio::error::operation_aborted error.

◆ close()

template<typename Rep , typename Executor >
error_code ozo::pooled_connection< Rep, Executor >::close
noexcept

Close the connection.

Any asynchronous operations will be cancelled immediately, and will complete with the boost::asio::error::operation_aborted error.

Returns
error_code - indicates what error occurred, if any. Note that, even if the function indicates an error, the underlying connection is closed.

References ozo::unwrap().

◆ get_error_context()

template<typename Rep , typename Executor = asio::io_context::executor_type>
const error_context_type& ozo::pooled_connection< Rep, Executor >::get_error_context ( ) const
noexcept

Get the additional context object for an error that occurred during the last operation on the connection.

Returns
const error_context& — additional context for the error

References ozo::unwrap().

◆ get_executor()

template<typename Rep , typename Executor = asio::io_context::executor_type>
executor_type ozo::pooled_connection< Rep, Executor >::get_executor ( ) const
noexcept

Get the executor associated with the object.

Returns
executor_type — executor object.

◆ is_bad()

template<typename Rep , typename Executor >
bool ozo::pooled_connection< Rep, Executor >::is_bad
noexcept

Determine whether the connection is in bad state.

Returns
false — connection established, and it is ok to execute operations
true — connection is not established, no operation shall be performed, but an error context may be obtained via get_error_context() and ozo::error_message().

Referenced by ozo::pooled_connection< Rep, Executor >::operator bool().

◆ is_open()

template<typename Rep , typename Executor = asio::io_context::executor_type>
bool ozo::pooled_connection< Rep, Executor >::is_open ( ) const
noexcept

Determine whether the connection is open.

Returns
false — connection is closed and no native handle associated with.
true — connection is open and there is a native handle associated with.

References ozo::pooled_connection< Rep, Executor >::native_handle().

◆ native_handle()

template<typename Rep , typename Executor >
pooled_connection< Rep, Executor >::native_handle_type ozo::pooled_connection< Rep, Executor >::native_handle
noexcept

Get native connection handle object.

This function may be used to obtain the underlying representation of the connection. This is intended to allow access to native libpq functionality that is not otherwise provided.

Returns
native_handle_type — native connection handle.

References ozo::unwrap().

Referenced by ozo::pooled_connection< Rep, Executor >::is_open().

◆ oid_map()

template<typename Rep , typename Executor = asio::io_context::executor_type>
const oid_map_type& ozo::pooled_connection< Rep, Executor >::oid_map ( ) const
noexcept

Get a reference to an oid map object for types that are used with the connection.

Returns
const oid_map_type& — reference on oid map object.

References ozo::unwrap().

◆ operator bool()

template<typename Rep , typename Executor = asio::io_context::executor_type>
ozo::pooled_connection< Rep, Executor >::operator bool ( ) const
noexcept

Determine whether the connection is not in bad state.

Returns
true — connection established, and it is ok to execute operations
false — connection is not established, no operation shall be performed, but an error context may be obtained via get_error_context() and ozo::error_message().

References ozo::pooled_connection< Rep, Executor >::is_bad().

◆ set_error_context()

template<typename Rep , typename Executor = asio::io_context::executor_type>
void ozo::pooled_connection< Rep, Executor >::set_error_context ( error_context_type  v = {})

Set the additional error context object. This function may be used to provide additional context-depended data that is related to the current operation error.

Parameters
v— new error context.