OZO 「お象」
Boost.Asio and libpq based asynchronous PostgreSQL unofficial header-only C++17 client library.
cancel.h
1 #pragma once
2 
3 #include <ozo/connection.h>
4 #include <ozo/time_traits.h>
5 
6 #include <libpq-fe.h>
7 #include <memory>
8 
9 namespace ozo {
10 
19 template <typename Executor>
21 public:
22  using executor_type = std::decay_t<Executor>;
23 
24  executor_type get_executor() const { return std::get<1>(v_);}
25 
26  using native_handle_type = PGcancel*;
27 
28  native_handle_type native_handle() const { return std::get<0>(v_).get();}
29 
30  cancel_handle(native_handle_type handle, Executor ex) : v_(handle, std::move(ex)) {}
31 
32 private:
33  struct deleter {
34  void operator()(native_handle_type h) const { PQfreeCancel(h); }
35  };
36 
37  std::tuple<std::unique_ptr<PGcancel, deleter>, executor_type> v_;
38 };
39 
56 template <typename Connection, typename Executor = boost::asio::system_executor>
57 inline cancel_handle<Executor> get_cancel_handle(const Connection& connection, Executor&& executor = Executor{});
58 
59 #ifdef OZO_DOCUMENTATION
60 
61 
141 template <typename Executor, typename TimeConstraint, typename CancelCompletionToken>
142 auto cancel(cancel_handle<Executor>&& handle, io_context& io, TimeConstraint time_constraint, CancelCompletionToken&& token);
143 
159 template <typename Executor, typename CancelCompletionToken>
160 auto cancel(cancel_handle<Executor>&& handle, CancelCompletionToken&& token);
161 #else
162 struct cancel_op {
163  template <typename Executor, typename TimeConstraint, typename CancelCompletionToken>
164  auto operator() (cancel_handle<Executor>&& handle, io_context& io,
165  TimeConstraint time_constraint, CancelCompletionToken&& token) const;
166 
167  template <typename Executor, typename CancelCompletionToken>
168  auto operator() (cancel_handle<Executor>&& handle, CancelCompletionToken&& token) const;
169 };
170 
171 constexpr cancel_op cancel;
172 
173 #endif
174 } // namespace ozo
175 
176 #include <ozo/impl/cancel.h>
ozo::cancel_handle
Cancel operation handle.
Definition: cancel.h:20
ozo::cancel_handle::native_handle_type
PGcancel * native_handle_type
Cancel operation native libpq handle type.
Definition: cancel.h:26
ozo::cancel
auto cancel(cancel_handle< Executor > &&handle, CancelCompletionToken &&token)
Cancel execution of current request on a database backend.
ozo::cancel_handle::get_executor
executor_type get_executor() const
Executor object cancel operation to run on.
Definition: cancel.h:24
ozo::cancel_handle::executor_type
std::decay_t< Executor > executor_type
Cancel operation Executor type.
Definition: cancel.h:22
ozo::cancel_handle::native_handle
native_handle_type native_handle() const
Cancel operation native libpq handle.
Definition: cancel.h:28
ozo::get_cancel_handle
cancel_handle< Executor > get_cancel_handle(const Connection &connection, Executor &&executor=Executor{})
Get cancel handle for the cancel operation.
Definition: cancel.h:157
Connection
Database connection concept.