Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-19 08:33:52

0001 //
0002 // Copyright (c) 2019-2024 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 
0008 #ifndef BOOST_MYSQL_IMPL_INTERNAL_SANSIO_RESET_CONNECTION_HPP
0009 #define BOOST_MYSQL_IMPL_INTERNAL_SANSIO_RESET_CONNECTION_HPP
0010 
0011 #include <boost/mysql/diagnostics.hpp>
0012 #include <boost/mysql/error_code.hpp>
0013 
0014 #include <boost/mysql/detail/algo_params.hpp>
0015 
0016 #include <boost/mysql/impl/internal/coroutine.hpp>
0017 #include <boost/mysql/impl/internal/protocol/deserialization.hpp>
0018 #include <boost/mysql/impl/internal/protocol/serialization.hpp>
0019 #include <boost/mysql/impl/internal/sansio/connection_state_data.hpp>
0020 
0021 namespace boost {
0022 namespace mysql {
0023 namespace detail {
0024 
0025 class read_reset_connection_response_algo
0026 {
0027     int resume_point_{0};
0028     diagnostics* diag_;
0029     std::uint8_t seqnum_{0};
0030 
0031 public:
0032     read_reset_connection_response_algo(diagnostics* diag, std::uint8_t seqnum) noexcept
0033         : diag_(diag), seqnum_(seqnum)
0034     {
0035     }
0036 
0037     next_action resume(connection_state_data& st, error_code ec)
0038     {
0039         switch (resume_point_)
0040         {
0041         case 0:
0042 
0043             // Read the reset response
0044             BOOST_MYSQL_YIELD(resume_point_, 1, st.read(seqnum_))
0045             if (ec)
0046                 return ec;
0047 
0048             // Verify it's what we expected
0049             ec = st.deserialize_ok(*diag_);
0050             if (!ec)
0051             {
0052                 // Reset was successful. Resetting changes the connection's character set
0053                 // to the server's default, which is an unknown value that doesn't have to match
0054                 // what was specified in handshake. As a safety measure, clear the current charset
0055                 st.current_charset = character_set{};
0056             }
0057 
0058             // Done
0059             return ec;
0060         }
0061 
0062         return next_action();
0063     }
0064 };
0065 
0066 inline run_pipeline_algo_params setup_reset_connection_pipeline(
0067     connection_state_data& st,
0068     reset_connection_algo_params params
0069 )
0070 {
0071     st.write_buffer.clear();
0072     st.shared_pipeline_stages[0] = {
0073         pipeline_stage_kind::reset_connection,
0074         serialize_top_level(reset_connection_command{}, st.write_buffer),
0075         {}
0076     };
0077     return {
0078         params.diag,
0079         st.write_buffer,
0080         {st.shared_pipeline_stages.data(), 1},
0081         nullptr
0082     };
0083 }
0084 
0085 }  // namespace detail
0086 }  // namespace mysql
0087 }  // namespace boost
0088 
0089 #endif /* INCLUDE_BOOST_MYSQL_DETAIL_NETWORK_ALGORITHMS_IMPL_CLOSE_STATEMENT_HPP_ */