File indexing completed on 2025-04-09 08:28:01
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_MYSQL_DETAIL_NEXT_ACTION_HPP
0009 #define BOOST_MYSQL_DETAIL_NEXT_ACTION_HPP
0010
0011 #include <boost/mysql/error_code.hpp>
0012
0013 #include <boost/assert.hpp>
0014 #include <boost/core/span.hpp>
0015
0016 #include <cstdint>
0017
0018 namespace boost {
0019 namespace mysql {
0020 namespace detail {
0021
0022 enum class next_action_type
0023 {
0024 none,
0025 write,
0026 read,
0027 ssl_handshake,
0028 ssl_shutdown,
0029 connect,
0030 close,
0031 };
0032
0033 class next_action
0034 {
0035 public:
0036 struct read_args_t
0037 {
0038 span<std::uint8_t> buffer;
0039 bool use_ssl;
0040 };
0041
0042 struct write_args_t
0043 {
0044 span<const std::uint8_t> buffer;
0045 bool use_ssl;
0046 };
0047
0048 next_action(error_code ec = {}) noexcept : type_(next_action_type::none), data_(ec) {}
0049
0050
0051 next_action_type type() const noexcept { return type_; }
0052 bool is_done() const noexcept { return type_ == next_action_type::none; }
0053 bool success() const noexcept { return is_done() && !data_.ec; }
0054
0055
0056 error_code error() const noexcept
0057 {
0058 BOOST_ASSERT(is_done());
0059 return data_.ec;
0060 }
0061 read_args_t read_args() const noexcept
0062 {
0063 BOOST_ASSERT(type_ == next_action_type::read);
0064 return data_.read_args;
0065 }
0066 write_args_t write_args() const noexcept
0067 {
0068 BOOST_ASSERT(type_ == next_action_type::write);
0069 return data_.write_args;
0070 }
0071
0072 static next_action connect() noexcept { return next_action(next_action_type::connect, data_t()); }
0073 static next_action read(read_args_t args) noexcept { return next_action(next_action_type::read, args); }
0074 static next_action write(write_args_t args) noexcept
0075 {
0076 return next_action(next_action_type::write, args);
0077 }
0078 static next_action ssl_handshake() noexcept
0079 {
0080 return next_action(next_action_type::ssl_handshake, data_t());
0081 }
0082 static next_action ssl_shutdown() noexcept
0083 {
0084 return next_action(next_action_type::ssl_shutdown, data_t());
0085 }
0086 static next_action close() noexcept { return next_action(next_action_type::close, data_t()); }
0087
0088 private:
0089 next_action_type type_{next_action_type::none};
0090 union data_t
0091 {
0092 error_code ec;
0093 read_args_t read_args;
0094 write_args_t write_args;
0095
0096 data_t() noexcept : ec(error_code()) {}
0097 data_t(error_code ec) noexcept : ec(ec) {}
0098 data_t(read_args_t args) noexcept : read_args(args) {}
0099 data_t(write_args_t args) noexcept : write_args(args) {}
0100 } data_;
0101
0102 next_action(next_action_type t, data_t data) noexcept : type_(t), data_(data) {}
0103 };
0104
0105 }
0106 }
0107 }
0108
0109 #endif