ping.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_PING_HPP
  8. #define BOOST_MYSQL_IMPL_INTERNAL_SANSIO_PING_HPP
  9. #include <boost/mysql/detail/algo_params.hpp>
  10. #include <boost/mysql/impl/internal/coroutine.hpp>
  11. #include <boost/mysql/impl/internal/protocol/serialization.hpp>
  12. #include <boost/mysql/impl/internal/sansio/connection_state_data.hpp>
  13. namespace boost {
  14. namespace mysql {
  15. namespace detail {
  16. class read_ping_response_algo
  17. {
  18. int resume_point_{0};
  19. diagnostics* diag_;
  20. std::uint8_t seqnum_{0};
  21. public:
  22. read_ping_response_algo(diagnostics* diag, std::uint8_t seqnum) noexcept : diag_(diag), seqnum_(seqnum) {}
  23. next_action resume(connection_state_data& st, 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
  33. return st.deserialize_ok(*diag_);
  34. }
  35. return next_action();
  36. }
  37. };
  38. inline run_pipeline_algo_params setup_ping_pipeline(connection_state_data& st, ping_algo_params params)
  39. {
  40. st.write_buffer.clear();
  41. auto seqnum = serialize_top_level(ping_command{}, st.write_buffer);
  42. st.shared_pipeline_stages[0] = {pipeline_stage_kind::ping, seqnum, {}};
  43. return {
  44. params.diag,
  45. st.write_buffer,
  46. {st.shared_pipeline_stages.data(), 1},
  47. nullptr
  48. };
  49. }
  50. } // namespace detail
  51. } // namespace mysql
  52. } // namespace boost
  53. #endif