reset_connection.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // Copyright (c) 2019-2024 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. diagnostics* diag_;
  23. std::uint8_t seqnum_{0};
  24. public:
  25. read_reset_connection_response_algo(diagnostics* diag, std::uint8_t seqnum) noexcept
  26. : diag_(diag), seqnum_(seqnum)
  27. {
  28. }
  29. next_action resume(connection_state_data& st, error_code ec)
  30. {
  31. switch (resume_point_)
  32. {
  33. case 0:
  34. // Read the reset response
  35. BOOST_MYSQL_YIELD(resume_point_, 1, st.read(seqnum_))
  36. if (ec)
  37. return ec;
  38. // Verify it's what we expected
  39. ec = st.deserialize_ok(*diag_);
  40. if (!ec)
  41. {
  42. // Reset was successful. Resetting changes the connection's character set
  43. // to the server's default, which is an unknown value that doesn't have to match
  44. // what was specified in handshake. As a safety measure, clear the current charset
  45. st.current_charset = character_set{};
  46. }
  47. // Done
  48. return ec;
  49. }
  50. return next_action();
  51. }
  52. };
  53. inline run_pipeline_algo_params setup_reset_connection_pipeline(
  54. connection_state_data& st,
  55. reset_connection_algo_params params
  56. )
  57. {
  58. st.write_buffer.clear();
  59. st.shared_pipeline_stages[0] = {
  60. pipeline_stage_kind::reset_connection,
  61. serialize_top_level(reset_connection_command{}, st.write_buffer),
  62. {}
  63. };
  64. return {
  65. params.diag,
  66. st.write_buffer,
  67. {st.shared_pipeline_stages.data(), 1},
  68. nullptr
  69. };
  70. }
  71. } // namespace detail
  72. } // namespace mysql
  73. } // namespace boost
  74. #endif /* INCLUDE_BOOST_MYSQL_DETAIL_NETWORK_ALGORITHMS_IMPL_CLOSE_STATEMENT_HPP_ */