Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:23:39

0001 //
0002 // ssl/detail/stream_core.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2025 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_SSL_DETAIL_STREAM_CORE_HPP
0012 #define BOOST_ASIO_SSL_DETAIL_STREAM_CORE_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 
0020 #include <boost/asio/ssl/detail/engine.hpp>
0021 #include <boost/asio/buffer.hpp>
0022 #include <boost/asio/steady_timer.hpp>
0023 
0024 #include <boost/asio/detail/push_options.hpp>
0025 
0026 namespace boost {
0027 namespace asio {
0028 namespace ssl {
0029 namespace detail {
0030 
0031 struct stream_core
0032 {
0033   // According to the OpenSSL documentation, this is the buffer size that is
0034   // sufficient to hold the largest possible TLS record.
0035   enum { max_tls_record_size = 17 * 1024 };
0036 
0037   template <typename Executor>
0038   stream_core(SSL_CTX* context, const Executor& ex)
0039     : engine_(context),
0040       pending_read_(ex),
0041       pending_write_(ex),
0042       output_buffer_space_(max_tls_record_size),
0043       output_buffer_(boost::asio::buffer(output_buffer_space_)),
0044       input_buffer_space_(max_tls_record_size),
0045       input_buffer_(boost::asio::buffer(input_buffer_space_))
0046   {
0047     pending_read_.expires_at(neg_infin());
0048     pending_write_.expires_at(neg_infin());
0049   }
0050 
0051   template <typename Executor>
0052   stream_core(SSL* ssl_impl, const Executor& ex)
0053     : engine_(ssl_impl),
0054       pending_read_(ex),
0055       pending_write_(ex),
0056       output_buffer_space_(max_tls_record_size),
0057       output_buffer_(boost::asio::buffer(output_buffer_space_)),
0058       input_buffer_space_(max_tls_record_size),
0059       input_buffer_(boost::asio::buffer(input_buffer_space_))
0060   {
0061     pending_read_.expires_at(neg_infin());
0062     pending_write_.expires_at(neg_infin());
0063   }
0064 
0065   stream_core(stream_core&& other)
0066     : engine_(static_cast<engine&&>(other.engine_)),
0067       pending_read_(
0068          static_cast<boost::asio::steady_timer&&>(
0069            other.pending_read_)),
0070       pending_write_(
0071          static_cast<boost::asio::steady_timer&&>(
0072            other.pending_write_)),
0073       output_buffer_space_(
0074           static_cast<std::vector<unsigned char>&&>(
0075             other.output_buffer_space_)),
0076       output_buffer_(other.output_buffer_),
0077       input_buffer_space_(
0078           static_cast<std::vector<unsigned char>&&>(
0079             other.input_buffer_space_)),
0080       input_buffer_(other.input_buffer_),
0081       input_(other.input_)
0082   {
0083     other.output_buffer_ = boost::asio::mutable_buffer(0, 0);
0084     other.input_buffer_ = boost::asio::mutable_buffer(0, 0);
0085     other.input_ = boost::asio::const_buffer(0, 0);
0086   }
0087 
0088   ~stream_core()
0089   {
0090   }
0091 
0092   stream_core& operator=(stream_core&& other)
0093   {
0094     if (this != &other)
0095     {
0096       engine_ = static_cast<engine&&>(other.engine_);
0097       pending_read_ =
0098         static_cast<boost::asio::steady_timer&&>(
0099           other.pending_read_);
0100       pending_write_ =
0101         static_cast<boost::asio::steady_timer&&>(
0102           other.pending_write_);
0103       output_buffer_space_ =
0104         static_cast<std::vector<unsigned char>&&>(
0105           other.output_buffer_space_);
0106       output_buffer_ = other.output_buffer_;
0107       input_buffer_space_ =
0108         static_cast<std::vector<unsigned char>&&>(
0109           other.input_buffer_space_);
0110       input_buffer_ = other.input_buffer_;
0111       input_ = other.input_;
0112       other.output_buffer_ = boost::asio::mutable_buffer(0, 0);
0113       other.input_buffer_ = boost::asio::mutable_buffer(0, 0);
0114       other.input_ = boost::asio::const_buffer(0, 0);
0115     }
0116     return *this;
0117   }
0118 
0119   // The SSL engine.
0120   engine engine_;
0121 
0122   // Timer used for storing queued read operations.
0123   boost::asio::steady_timer pending_read_;
0124 
0125   // Timer used for storing queued write operations.
0126   boost::asio::steady_timer pending_write_;
0127 
0128   // Helper function for obtaining a time value that always fires.
0129   static boost::asio::steady_timer::time_point neg_infin()
0130   {
0131     return (boost::asio::steady_timer::time_point::min)();
0132   }
0133 
0134   // Helper function for obtaining a time value that never fires.
0135   static boost::asio::steady_timer::time_point pos_infin()
0136   {
0137     return (boost::asio::steady_timer::time_point::max)();
0138   }
0139 
0140   // Helper function to get a timer's expiry time.
0141   static boost::asio::steady_timer::time_point expiry(
0142       const boost::asio::steady_timer& timer)
0143   {
0144     return timer.expiry();
0145   }
0146 
0147   // Buffer space used to prepare output intended for the transport.
0148   std::vector<unsigned char> output_buffer_space_;
0149 
0150   // A buffer that may be used to prepare output intended for the transport.
0151   boost::asio::mutable_buffer output_buffer_;
0152 
0153   // Buffer space used to read input intended for the engine.
0154   std::vector<unsigned char> input_buffer_space_;
0155 
0156   // A buffer that may be used to read input intended for the engine.
0157   boost::asio::mutable_buffer input_buffer_;
0158 
0159   // The buffer pointing to the engine's unconsumed input.
0160   boost::asio::const_buffer input_;
0161 };
0162 
0163 } // namespace detail
0164 } // namespace ssl
0165 } // namespace asio
0166 } // namespace boost
0167 
0168 #include <boost/asio/detail/pop_options.hpp>
0169 
0170 #endif // BOOST_ASIO_SSL_DETAIL_STREAM_CORE_HPP