Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-17 09:00:17

0001 //
0002 // Copyright (c) 2025 Marcelo Zimbres Silva (mzimbres@gmail.com),
0003 // Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
0004 //
0005 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0006 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 //
0008 
0009 #ifndef BOOST_REDIS_CONNECT_FSM_HPP
0010 #define BOOST_REDIS_CONNECT_FSM_HPP
0011 
0012 #include <boost/redis/config.hpp>
0013 
0014 #include <boost/asio/cancellation_type.hpp>
0015 #include <boost/asio/ip/tcp.hpp>
0016 #include <boost/system/error_code.hpp>
0017 
0018 // Sans-io algorithm for redis_stream::async_connect, as a finite state machine
0019 
0020 namespace boost::redis::detail {
0021 
0022 struct buffered_logger;
0023 
0024 // What transport is redis_stream using?
0025 enum class transport_type
0026 {
0027    tcp,          // plaintext TCP
0028    tcp_tls,      // TLS over TCP
0029    unix_socket,  // UNIX domain sockets
0030 };
0031 
0032 struct redis_stream_state {
0033    transport_type type{transport_type::tcp};
0034    bool ssl_stream_used{false};
0035 };
0036 
0037 // What should we do next?
0038 enum class connect_action_type
0039 {
0040    unix_socket_close,    // Close the UNIX socket, to discard state
0041    unix_socket_connect,  // Connect to the UNIX socket
0042    tcp_resolve,          // Name resolution
0043    tcp_connect,          // TCP connect
0044    ssl_stream_reset,     // Re-create the SSL stream, to discard state
0045    ssl_handshake,        // SSL handshake
0046    done,                 // Complete the async op
0047 };
0048 
0049 struct connect_action {
0050    connect_action_type type;
0051    system::error_code ec;
0052 
0053    connect_action(connect_action_type type) noexcept
0054    : type{type}
0055    { }
0056 
0057    connect_action(system::error_code ec) noexcept
0058    : type{connect_action_type::done}
0059    , ec{ec}
0060    { }
0061 };
0062 
0063 class connect_fsm {
0064    int resume_point_{0};
0065    const config* cfg_{nullptr};
0066    buffered_logger* lgr_{nullptr};
0067 
0068 public:
0069    connect_fsm(const config& cfg, buffered_logger& lgr) noexcept
0070    : cfg_(&cfg)
0071    , lgr_(&lgr)
0072    { }
0073 
0074    const config& get_config() const { return *cfg_; }
0075 
0076    connect_action resume(
0077       system::error_code ec,
0078       const asio::ip::tcp::resolver::results_type& resolver_results,
0079       redis_stream_state& st,
0080       asio::cancellation_type_t cancel_state);
0081 
0082    connect_action resume(
0083       system::error_code ec,
0084       const asio::ip::tcp::endpoint& selected_endpoint,
0085       redis_stream_state& st,
0086       asio::cancellation_type_t cancel_state);
0087 
0088    connect_action resume(
0089       system::error_code ec,
0090       redis_stream_state& st,
0091       asio::cancellation_type_t cancel_state);
0092 
0093 };  // namespace boost::redis::detail
0094 
0095 }  // namespace boost::redis::detail
0096 
0097 #endif