Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:42:39

0001 //
0002 // Copyright (c) 2019-2023 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
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     // SSL
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     // Reading
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     // Writing
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     // Connect and close - these apply only to SocketStream's
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 }  // namespace detail
0079 }  // namespace mysql
0080 }  // namespace boost
0081 
0082 #endif