File indexing completed on 2026-08-17 09:00:18
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_REDIS_READER_FSM_HPP
0008 #define BOOST_REDIS_READER_FSM_HPP
0009
0010 #include <boost/redis/detail/connection_state.hpp>
0011 #include <boost/redis/detail/multiplexer.hpp>
0012
0013 #include <boost/asio/cancellation_type.hpp>
0014 #include <boost/system/error_code.hpp>
0015
0016 #include <chrono>
0017 #include <cstddef>
0018
0019 namespace boost::redis::detail {
0020
0021 class read_buffer;
0022
0023 class reader_fsm {
0024 public:
0025 class action {
0026 public:
0027 enum class type
0028 {
0029 read_some,
0030 notify_push_receiver,
0031 done,
0032 };
0033
0034 action(system::error_code ec) noexcept
0035 : type_(type::done)
0036 , ec_(ec)
0037 { }
0038
0039 static action read_some(std::chrono::steady_clock::duration timeout) { return {timeout}; }
0040
0041 static action notify_push_receiver(std::size_t bytes) { return {bytes}; }
0042
0043 type get_type() const { return type_; }
0044
0045 system::error_code error() const
0046 {
0047 BOOST_ASSERT(type_ == type::done);
0048 return ec_;
0049 }
0050
0051 std::chrono::steady_clock::duration timeout() const
0052 {
0053 BOOST_ASSERT(type_ == type::read_some);
0054 return timeout_;
0055 }
0056
0057 std::size_t push_size() const
0058 {
0059 BOOST_ASSERT(type_ == type::notify_push_receiver);
0060 return push_size_;
0061 }
0062
0063 private:
0064 action(std::size_t push_size) noexcept
0065 : type_(type::notify_push_receiver)
0066 , push_size_(push_size)
0067 { }
0068
0069 action(std::chrono::steady_clock::duration t) noexcept
0070 : type_(type::read_some)
0071 , timeout_(t)
0072 { }
0073
0074 type type_;
0075 union {
0076 system::error_code ec_;
0077 std::chrono::steady_clock::duration timeout_;
0078 std::size_t push_size_{};
0079 };
0080 };
0081
0082 action resume(
0083 connection_state& st,
0084 std::size_t bytes_read,
0085 system::error_code ec,
0086 asio::cancellation_type_t cancel_state);
0087
0088 reader_fsm() = default;
0089
0090 private:
0091 int resume_point_{0};
0092 std::pair<consume_result, std::size_t> res_{consume_result::needs_more, 0u};
0093 };
0094
0095 }
0096
0097 #endif