reset_connection.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // Copyright (c) 2019-2025 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. #ifndef BOOST_MYSQL_IMPL_INTERNAL_SANSIO_RESET_CONNECTION_HPP
  8. #define BOOST_MYSQL_IMPL_INTERNAL_SANSIO_RESET_CONNECTION_HPP
  9. #include <boost/mysql/diagnostics.hpp>
  10. #include <boost/mysql/error_code.hpp>
  11. #include <boost/mysql/detail/algo_params.hpp>
  12. #include <boost/mysql/impl/internal/coroutine.hpp>
  13. #include <boost/mysql/impl/internal/protocol/deserialization.hpp>
  14. #include <boost/mysql/impl/internal/protocol/serialization.hpp>
  15. #include <boost/mysql/impl/internal/sansio/connection_state_data.hpp>
  16. namespace boost {
  17. namespace mysql {
  18. namespace detail {
  19. class read_reset_connection_response_algo
  20. {
  21. int resume_point_{0};
  22. std::uint8_t seqnum_{0};
  23. public:
  24. read_reset_connection_response_algo(std::uint8_t seqnum) noexcept : seqnum_(seqnum) {}
  25. next_action resume(connection_state_data& st, diagnostics& diag, error_code ec)
  26. {
  27. switch (resume_point_)
  28. {
  29. case 0:
  30. // Read the reset response
  31. BOOST_MYSQL_YIELD(resume_point_, 1, st.read(seqnum_))
  32. if (ec)
  33. return ec;
  34. // Verify it's what we expected
  35. ec = st.deserialize_ok(diag);
  36. if (!ec)
  37. {
  38. // Reset was successful. Resetting changes the connection's character set
  39. // to the server's default, which is an unknown value that doesn't have to match
  40. // what was specified in handshake. As a safety measure, clear the current charset
  41. st.current_charset = character_set{};
  42. }
  43. // Done
  44. }
  45. return ec;
  46. }
  47. };
  48. inline run_pipeline_algo_params setup_reset_connection_pipeline(connection_state_data& st)
  49. {
  50. // reset_connection request is fixed size and small, so we don't enforce any buffer limit
  51. st.write_buffer.clear();
  52. st.shared_pipeline_stages[0] = {
  53. pipeline_stage_kind::reset_connection,
  54. serialize_top_level_checked(reset_connection_command{}, st.write_buffer),
  55. {}
  56. };
  57. return {
  58. st.write_buffer,
  59. {st.shared_pipeline_stages.data(), 1},
  60. nullptr
  61. };
  62. }
  63. } // namespace detail
  64. } // namespace mysql
  65. } // namespace boost
  66. #endif /* INCLUDE_BOOST_MYSQL_DETAIL_NETWORK_ALGORITHMS_IMPL_CLOSE_STATEMENT_HPP_ */