Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 08:42:57

0001 //
0002 // Copyright (c) 2019-2025 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     std::uint8_t seqnum_{0};
0029 
0030 public:
0031     read_reset_connection_response_algo(std::uint8_t seqnum) noexcept : seqnum_(seqnum) {}
0032 
0033     next_action resume(connection_state_data& st, diagnostics& diag, error_code ec)
0034     {
0035         switch (resume_point_)
0036         {
0037         case 0:
0038 
0039             // Read the reset response
0040             BOOST_MYSQL_YIELD(resume_point_, 1, st.read(seqnum_))
0041             if (ec)
0042                 return ec;
0043 
0044             // Verify it's what we expected
0045             ec = st.deserialize_ok(diag);
0046             if (!ec)
0047             {
0048                 // Reset was successful. Resetting changes the connection's character set
0049                 // to the server's default, which is an unknown value that doesn't have to match
0050                 // what was specified in handshake. As a safety measure, clear the current charset
0051                 st.current_charset = character_set{};
0052             }
0053 
0054             // Done
0055         }
0056 
0057         return ec;
0058     }
0059 };
0060 
0061 inline run_pipeline_algo_params setup_reset_connection_pipeline(connection_state_data& st)
0062 {
0063     // reset_connection request is fixed size and small, so we don't enforce any buffer limit
0064     st.write_buffer.clear();
0065     st.shared_pipeline_stages[0] = {
0066         pipeline_stage_kind::reset_connection,
0067         serialize_top_level_checked(reset_connection_command{}, st.write_buffer),
0068         {}
0069     };
0070     return {
0071         st.write_buffer,
0072         {st.shared_pipeline_stages.data(), 1},
0073         nullptr
0074     };
0075 }
0076 
0077 }  // namespace detail
0078 }  // namespace mysql
0079 }  // namespace boost
0080 
0081 #endif /* INCLUDE_BOOST_MYSQL_DETAIL_NETWORK_ALGORITHMS_IMPL_CLOSE_STATEMENT_HPP_ */