File indexing completed on 2025-01-18 09:42:39
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_MYSQL_DETAIL_ANY_STREAM_HPP
0009 #define BOOST_MYSQL_DETAIL_ANY_STREAM_HPP
0010
0011 #include <boost/mysql/error_code.hpp>
0012
0013 #include <boost/asio/any_completion_handler.hpp>
0014 #include <boost/asio/any_io_executor.hpp>
0015 #include <boost/asio/buffer.hpp>
0016
0017 #include <cstddef>
0018
0019 namespace boost {
0020 namespace mysql {
0021 namespace detail {
0022
0023 class any_stream
0024 {
0025 public:
0026 any_stream(bool supports_ssl) noexcept
0027 : ssl_state_(supports_ssl ? ssl_state::inactive : ssl_state::unsupported)
0028 {
0029 }
0030 bool ssl_active() const noexcept { return ssl_state_ == ssl_state::active; }
0031 void reset_ssl_active() noexcept
0032 {
0033 if (ssl_state_ == ssl_state::active)
0034 ssl_state_ = ssl_state::inactive;
0035 }
0036 void set_ssl_active() noexcept
0037 {
0038 BOOST_ASSERT(ssl_state_ != ssl_state::unsupported);
0039 ssl_state_ = ssl_state::active;
0040 }
0041 bool supports_ssl() const noexcept { return ssl_state_ != ssl_state::unsupported; }
0042
0043 using executor_type = asio::any_io_executor;
0044
0045 virtual ~any_stream() {}
0046
0047 virtual executor_type get_executor() = 0;
0048
0049
0050 virtual void handshake(error_code& ec) = 0;
0051 virtual void async_handshake(asio::any_completion_handler<void(error_code)>) = 0;
0052 virtual void shutdown(error_code& ec) = 0;
0053 virtual void async_shutdown(asio::any_completion_handler<void(error_code)>) = 0;
0054
0055
0056 virtual std::size_t read_some(asio::mutable_buffer, error_code& ec) = 0;
0057 virtual void async_read_some(asio::mutable_buffer, asio::any_completion_handler<void(error_code, std::size_t)>) = 0;
0058
0059
0060 virtual std::size_t write_some(asio::const_buffer, error_code& ec) = 0;
0061 virtual void async_write_some(asio::const_buffer, asio::any_completion_handler<void(error_code, std::size_t)>) = 0;
0062
0063
0064 virtual void connect(const void* endpoint, error_code& ec) = 0;
0065 virtual void async_connect(const void* endpoint, asio::any_completion_handler<void(error_code)>) = 0;
0066 virtual void close(error_code& ec) = 0;
0067 virtual bool is_open() const noexcept = 0;
0068
0069 private:
0070 enum class ssl_state
0071 {
0072 inactive,
0073 active,
0074 unsupported
0075 } ssl_state_;
0076 };
0077
0078 }
0079 }
0080 }
0081
0082 #endif