7#ifndef BOOST_REDIS_RESOLVER_HPP
8#define BOOST_REDIS_RESOLVER_HPP
10#include <boost/redis/config.hpp>
11#include <boost/redis/detail/helper.hpp>
12#include <boost/redis/error.hpp>
13#include <boost/asio/compose.hpp>
14#include <boost/asio/coroutine.hpp>
15#include <boost/asio/experimental/parallel_group.hpp>
16#include <boost/asio/ip/tcp.hpp>
17#include <boost/asio/steady_timer.hpp>
21namespace boost::redis::detail
24template <
class Resolver>
26 Resolver* resv_ =
nullptr;
27 asio::coroutine coro{};
30 void operator()( Self& self
31 , std::array<std::size_t, 2> order = {}
32 , system::error_code ec1 = {}
33 , asio::ip::tcp::resolver::results_type res = {}
34 , system::error_code ec2 = {})
36 BOOST_ASIO_CORO_REENTER (coro)
38 resv_->timer_.expires_after(resv_->timeout_);
41 asio::experimental::make_parallel_group(
44 return resv_->resv_.async_resolve(resv_->addr_.host, resv_->addr_.port, token);
46 [
this](
auto token) {
return resv_->timer_.async_wait(token);}
48 asio::experimental::wait_for_one(),
51 if (is_cancelled(self)) {
52 self.complete(asio::error::operation_aborted);
59 resv_->results_ = res;
75 default: BOOST_ASSERT(
false);
81template <
class Executor>
85 asio::basic_waitable_timer<
86 std::chrono::steady_clock,
87 asio::wait_traits<std::chrono::steady_clock>,
90 resolver(Executor ex) : resv_{ex} , timer_{ex} {}
92 template <
class CompletionToken>
93 auto async_resolve(CompletionToken&& token)
95 return asio::async_compose
97 , void(system::error_code)
98 >(resolve_op<resolver>{
this}, token, resv_);
115 auto const& results() const noexcept
118 void set_config(config
const& cfg)
121 timeout_ = cfg.resolve_timeout;
125 using resolver_type = asio::ip::basic_resolver<asio::ip::tcp, Executor>;
126 template <
class>
friend struct resolve_op;
131 std::chrono::steady_clock::duration timeout_;
132 asio::ip::tcp::resolver::results_type results_;
operation
Connection operations that can be cancelled.
@ resolve_timeout
Resolve timeout.
@ resolve
Resolve operation.
@ all
Refers to all operations.