// // Copyright (c) 2019-2024 Ruben Perez Hidalgo (rubenperez038 at gmail dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_MYSQL_IMPL_INTERNAL_SANSIO_CONNECTION_STATE_HPP #define BOOST_MYSQL_IMPL_INTERNAL_SANSIO_CONNECTION_STATE_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace boost { namespace mysql { namespace detail { // clang-format off template struct get_algo; template <> struct get_algo { using type = connect_algo; }; template <> struct get_algo { using type = handshake_algo; }; template <> struct get_algo { using type = execute_algo; }; template <> struct get_algo { using type = start_execution_algo; }; template <> struct get_algo { using type = read_resultset_head_algo; }; template <> struct get_algo { using type = read_some_rows_algo; }; template <> struct get_algo { using type = read_some_rows_dynamic_algo; }; template <> struct get_algo { using type = prepare_statement_algo; }; template <> struct get_algo { using type = set_character_set_algo; }; template <> struct get_algo { using type = quit_connection_algo; }; template <> struct get_algo { using type = close_connection_algo; }; template <> struct get_algo { using type = run_pipeline_algo; }; template using get_algo_t = typename get_algo::type; // clang-format on class connection_state { // Helper template using make_any_algo_type = variant2::variant...>; using any_algo = make_any_algo_type< connect_algo, handshake_algo, execute_algo, start_execution_algo, read_resultset_head_algo, read_some_rows_algo, read_some_rows_dynamic_algo, prepare_statement_algo, set_character_set_algo, quit_connection_algo, close_connection_algo, run_pipeline_algo>; connection_state_data st_data_; any_algo algo_; public: // We initialize the algo state with a dummy value. This will be overwritten // by setup() before the first algorithm starts running. Doing this avoids // the need for a special null algo connection_state(std::size_t read_buffer_size, std::size_t max_buffer_size, bool transport_supports_ssl) : st_data_(read_buffer_size, max_buffer_size, transport_supports_ssl), algo_(top_level_algo( st_data_, quit_connection_algo_params{&st_data_.shared_diag} )) { } const connection_state_data& data() const { return st_data_; } connection_state_data& data() { return st_data_; } template any_resumable_ref setup(AlgoParams params) { return any_resumable_ref(algo_.emplace>>(st_data_, params)); } any_resumable_ref setup(close_statement_algo_params params) { return setup(setup_close_statement_pipeline(st_data_, params)); } any_resumable_ref setup(reset_connection_algo_params params) { return setup(setup_reset_connection_pipeline(st_data_, params)); } any_resumable_ref setup(ping_algo_params params) { return setup(setup_ping_pipeline(st_data_, params)); } template typename AlgoParams::result_type result() const { return variant2::get>>(algo_).inner_algo().result(st_data_); } }; } // namespace detail } // namespace mysql } // namespace boost #endif