7#ifndef BOOST_REDIS_SSL_CONNECTOR_HPP
8#define BOOST_REDIS_SSL_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>
18#include <boost/asio/ssl.hpp>
22namespace boost::redis::detail
25template <
class Handshaker,
class Stream>
27 Handshaker* hsher_ =
nullptr;
28 Stream* stream_ =
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 , system::error_code
const& ec2 = {})
37 BOOST_ASIO_CORO_REENTER (coro)
39 hsher_->timer_.expires_after(hsher_->timeout_);
42 asio::experimental::make_parallel_group(
43 [
this](
auto token) {
return stream_->async_handshake(asio::ssl::stream_base::client, token); },
44 [
this](
auto token) {
return hsher_->timer_.async_wait(token);}
46 asio::experimental::wait_for_one(),
49 if (is_cancelled(self)) {
50 self.complete(asio::error::operation_aborted);
67 default: BOOST_ASSERT(
false);
73template <
class Executor>
77 asio::basic_waitable_timer<
78 std::chrono::steady_clock,
79 asio::wait_traits<std::chrono::steady_clock>,
82 handshaker(Executor ex)
86 template <
class Stream,
class CompletionToken>
88 async_handshake(Stream& stream, CompletionToken&& token)
90 return asio::async_compose
92 , void(system::error_code)
93 >(handshake_op<handshaker, Stream>{
this, &stream}, token, timer_);
109 constexpr bool is_dummy() const noexcept
112 void set_config(config
const& cfg)
113 { timeout_ = cfg.ssl_handshake_timeout; }
116 template <
class,
class>
friend struct handshake_op;
119 std::chrono::steady_clock::duration timeout_;
operation
Connection operations that can be cancelled.
@ ssl_handshake_timeout
SSL handshake timeout.
@ ssl_handshake
SSL handshake operation.
@ all
Refers to all operations.