ping.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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_PING_HPP
  8. #define BOOST_MYSQL_IMPL_INTERNAL_SANSIO_PING_HPP
  9. #include <boost/mysql/diagnostics.hpp>
  10. #include <boost/mysql/detail/algo_params.hpp>
  11. #include <boost/mysql/impl/internal/coroutine.hpp>
  12. #include <boost/mysql/impl/internal/protocol/serialization.hpp>
  13. #include <boost/mysql/impl/internal/sansio/connection_state_data.hpp>
  14. namespace boost {
  15. namespace mysql {
  16. namespace detail {
  17. class read_ping_response_algo
  18. {
  19. int resume_point_{0};
  20. std::uint8_t seqnum_{0};
  21. public:
  22. read_ping_response_algo(std::uint8_t seqnum) noexcept : seqnum_(seqnum) {}
  23. next_action resume(connection_state_data& st, diagnostics& diag, error_code ec)
  24. {
  25. switch (resume_point_)
  26. {
  27. case 0:
  28. // Issue a read
  29. BOOST_MYSQL_YIELD(resume_point_, 1, st.read(seqnum_))
  30. if (ec)
  31. return ec;
  32. // Process the OK packet and done
  33. ec = st.deserialize_ok(diag);
  34. }
  35. return ec;
  36. }
  37. };
  38. inline run_pipeline_algo_params setup_ping_pipeline(connection_state_data& st)
  39. {
  40. // The ping request is fixed size and small. No buffer limit is enforced on it.
  41. st.write_buffer.clear();
  42. st.shared_pipeline_stages[0] = {
  43. pipeline_stage_kind::ping,
  44. serialize_top_level_checked(ping_command{}, st.write_buffer),
  45. {}
  46. };
  47. return {
  48. st.write_buffer,
  49. {st.shared_pipeline_stages.data(), 1},
  50. nullptr
  51. };
  52. }
  53. } // namespace detail
  54. } // namespace mysql
  55. } // namespace boost
  56. #endif