7#ifndef BOOST_REDIS_CONNECTOR_HPP
8#define BOOST_REDIS_CONNECTOR_HPP
10#include <boost/redis/detail/helper.hpp>
11#include <boost/redis/error.hpp>
12#include <boost/asio/compose.hpp>
13#include <boost/asio/connect.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 Connector,
class Stream>
26 Connector* ctor_ =
nullptr;
27 Stream* stream =
nullptr;
28 asio::ip::tcp::resolver::results_type
const* res_ =
nullptr;
29 asio::coroutine coro{};
32 void operator()( Self& self
33 , std::array<std::size_t, 2>
const& order = {}
34 , system::error_code
const& ec1 = {}
35 , asio::ip::tcp::endpoint
const& ep= {}
36 , system::error_code
const& ec2 = {})
38 BOOST_ASIO_CORO_REENTER (coro)
40 ctor_->timer_.expires_after(ctor_->timeout_);
43 asio::experimental::make_parallel_group(
46 auto f = [](system::error_code
const&,
auto const&) {
return true; };
47 return asio::async_connect(*stream, *res_, f, token);
49 [
this](
auto token) {
return ctor_->timer_.async_wait(token);}
51 asio::experimental::wait_for_one(),
54 if (is_cancelled(self)) {
55 self.complete(asio::error::operation_aborted);
61 ctor_->endpoint_ = ep;
73 default: BOOST_ASSERT(
false);
79template <
class Executor>
83 asio::basic_waitable_timer<
84 std::chrono::steady_clock,
85 asio::wait_traits<std::chrono::steady_clock>,
88 connector(Executor ex)
92 void set_config(config
const& cfg)
93 { timeout_ = cfg.connect_timeout; }
95 template <
class Stream,
class CompletionToken>
99 asio::ip::tcp::resolver::results_type
const& res,
100 CompletionToken&& token)
102 return asio::async_compose
104 , void(system::error_code)
105 >(connect_op<connector, Stream>{
this, &stream, &res}, token, timer_);
121 auto const& endpoint() const noexcept {
return endpoint_;}
124 template <
class,
class>
friend struct connect_op;
127 std::chrono::steady_clock::duration timeout_ = std::chrono::seconds{2};
128 asio::ip::tcp::endpoint endpoint_;
operation
Connection operations that can be cancelled.
@ connect_timeout
Connect timeout.
@ all
Refers to all operations.
@ connect
Connect operation.