run_fsm.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // Copyright (c) 2025 Marcelo Zimbres Silva (mzimbres@gmail.com),
  3. // Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. #ifndef BOOST_REDIS_RUN_FSM_HPP
  9. #define BOOST_REDIS_RUN_FSM_HPP
  10. #include <boost/asio/cancellation_type.hpp>
  11. #include <boost/system/error_code.hpp>
  12. // Sans-io algorithm for async_run, as a finite state machine
  13. namespace boost::redis::detail {
  14. // Forward decls
  15. struct connection_state;
  16. // What should we do next?
  17. enum class run_action_type
  18. {
  19. done, // Call the final handler
  20. immediate, // Call asio::async_immediate
  21. connect, // Transport connection establishment
  22. parallel_group, // Run the reader, writer and friends
  23. cancel_receive, // Cancel the receiver channel
  24. wait_for_reconnection, // Sleep for the reconnection period
  25. };
  26. struct run_action {
  27. run_action_type type;
  28. system::error_code ec;
  29. run_action(run_action_type type) noexcept
  30. : type{type}
  31. { }
  32. run_action(system::error_code ec) noexcept
  33. : type{run_action_type::done}
  34. , ec{ec}
  35. { }
  36. };
  37. class run_fsm {
  38. int resume_point_{0};
  39. system::error_code stored_ec_;
  40. public:
  41. run_fsm() = default;
  42. run_action resume(
  43. connection_state& st,
  44. system::error_code ec,
  45. asio::cancellation_type_t cancel_state);
  46. };
  47. } // namespace boost::redis::detail
  48. #endif // BOOST_REDIS_CONNECTOR_HPP