diff --git a/include/boost/redis/detail/connection_base.hpp b/include/boost/redis/detail/connection_base.hpp index 94f7b707..fbfd4337 100644 --- a/include/boost/redis/detail/connection_base.hpp +++ b/include/boost/redis/detail/connection_base.hpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -350,7 +349,6 @@ class connection_base { , writer_timer_{ex} , receive_channel_{ex, 256} , resv_{ex} - , ssl_handshaker_{ex} , health_checker_{ex} , runner_{ex, {}} , dbuf_{read_buffer_, max_read_size} @@ -385,9 +383,6 @@ class connection_base { case operation::resolve: resv_.cancel(); break; - case operation::ssl_handshake: - ssl_handshaker_.cancel(); - break; case operation::exec: cancel_unwritten_requests(); break; @@ -405,7 +400,6 @@ class connection_base { break; case operation::all: resv_.cancel(); - ssl_handshaker_.cancel(); cfg_.reconnect_wait_interval = std::chrono::seconds::zero(); health_checker_.cancel(); cancel_run(); // run @@ -469,7 +463,6 @@ class connection_base { cfg_ = cfg; resv_.set_config(cfg); ctor_.set_config(cfg); - ssl_handshaker_.set_config(cfg); health_checker_.set_config(cfg); runner_.set_config(cfg); l.set_prefix(cfg.log_prefix); @@ -496,7 +489,6 @@ class connection_base { private: using receive_channel_type = asio::experimental::channel; using resolver_type = resolver; - using handshaker_type = handshaker; using health_checker_type = health_checker; using runner_type = runner; using adapter_type = std::function const&, system::error_code&)>; @@ -906,7 +898,6 @@ class connection_base { receive_channel_type receive_channel_; resolver_type resv_; connector ctor_; - handshaker_type ssl_handshaker_; health_checker_type health_checker_; runner_type runner_; receiver_adapter_type receive_adapter_; diff --git a/include/boost/redis/detail/handshaker.hpp b/include/boost/redis/detail/handshaker.hpp deleted file mode 100644 index c5c73ffe..00000000 --- a/include/boost/redis/detail/handshaker.hpp +++ /dev/null @@ -1,114 +0,0 @@ -/* Copyright (c) 2018-2024 Marcelo Zimbres Silva (mzimbres@gmail.com) - * - * Distributed under the Boost Software License, Version 1.0. (See - * accompanying file LICENSE.txt) - */ - -#ifndef BOOST_REDIS_SSL_CONNECTOR_HPP -#define BOOST_REDIS_SSL_CONNECTOR_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace boost::redis::detail -{ - -template -struct handshake_op { - Handshaker* hsher_ = nullptr; - Stream* stream_ = nullptr; - asio::coroutine coro{}; - - template - void operator()( Self& self - , std::array const& order = {} - , system::error_code const& ec1 = {} - , system::error_code const& ec2 = {}) - { - BOOST_ASIO_CORO_REENTER (coro) - { - hsher_->timer_.expires_after(hsher_->timeout_); - - BOOST_ASIO_CORO_YIELD - asio::experimental::make_parallel_group( - [this](auto token) { return stream_->async_handshake(asio::ssl::stream_base::client, token); }, - [this](auto token) { return hsher_->timer_.async_wait(token);} - ).async_wait( - asio::experimental::wait_for_one(), - std::move(self)); - - if (is_cancelled(self)) { - self.complete(asio::error::operation_aborted); - return; - } - - switch (order[0]) { - case 0: { - self.complete(ec1); - } break; - case 1: - { - if (ec2) { - self.complete(ec2); - } else { - self.complete(error::ssl_handshake_timeout); - } - } break; - - default: BOOST_ASSERT(false); - } - } - } -}; - -template -class handshaker { -public: - using timer_type = - asio::basic_waitable_timer< - std::chrono::steady_clock, - asio::wait_traits, - Executor>; - - handshaker(Executor ex) - : timer_{ex} - {} - - template - auto - async_handshake(Stream& stream, CompletionToken&& token) - { - return asio::async_compose - < CompletionToken - , void(system::error_code) - >(handshake_op{this, &stream}, token, timer_); - } - - void cancel() - { timer_.cancel(); } - - constexpr bool is_dummy() const noexcept - {return false;} - - void set_config(config const& cfg) - { timeout_ = cfg.ssl_handshake_timeout; } - -private: - template friend struct handshake_op; - - timer_type timer_; - std::chrono::steady_clock::duration timeout_; -}; - -} // boost::redis::detail - -#endif // BOOST_REDIS_SSL_CONNECTOR_HPP diff --git a/include/boost/redis/detail/runner.hpp b/include/boost/redis/detail/runner.hpp index bbbdf881..42553bd3 100644 --- a/include/boost/redis/detail/runner.hpp +++ b/include/boost/redis/detail/runner.hpp @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #include #include @@ -120,9 +122,16 @@ class runner_op { if (conn_->use_ssl()) { BOOST_ASIO_CORO_YIELD - conn_->ssl_handshaker_.async_handshake( - conn_->next_layer(), - asio::prepend(std::move(self), order_t {})); + conn_->next_layer().async_handshake( + asio::ssl::stream_base::client, + asio::prepend( + asio::cancel_after( + runner_->cfg_.ssl_handshake_timeout, + std::move(self) + ), + order_t {} + ) + ); logger_.on_ssl_handshake(ec0);