2 // ssl/detail/stream_core.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_ASIO_SSL_DETAIL_STREAM_CORE_HPP
12 #define BOOST_ASIO_SSL_DETAIL_STREAM_CORE_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
20 #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
21 # include <boost/asio/deadline_timer.hpp>
22 #else // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
23 # include <boost/asio/steady_timer.hpp>
24 #endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
25 #include <boost/asio/ssl/detail/engine.hpp>
26 #include <boost/asio/buffer.hpp>
28 #include <boost/asio/detail/push_options.hpp>
37 // According to the OpenSSL documentation, this is the buffer size that is
38 // sufficient to hold the largest possible TLS record.
39 enum { max_tls_record_size = 17 * 1024 };
41 template <typename Executor>
42 stream_core(SSL_CTX* context, const Executor& ex)
46 output_buffer_space_(max_tls_record_size),
47 output_buffer_(boost::asio::buffer(output_buffer_space_)),
48 input_buffer_space_(max_tls_record_size),
49 input_buffer_(boost::asio::buffer(input_buffer_space_))
51 pending_read_.expires_at(neg_infin());
52 pending_write_.expires_at(neg_infin());
55 #if defined(BOOST_ASIO_HAS_MOVE)
56 stream_core(stream_core&& other)
57 : engine_(BOOST_ASIO_MOVE_CAST(engine)(other.engine_)),
58 #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
60 BOOST_ASIO_MOVE_CAST(boost::asio::deadline_timer)(
61 other.pending_read_)),
63 BOOST_ASIO_MOVE_CAST(boost::asio::deadline_timer)(
64 other.pending_write_)),
65 #else // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
67 BOOST_ASIO_MOVE_CAST(boost::asio::steady_timer)(
68 other.pending_read_)),
70 BOOST_ASIO_MOVE_CAST(boost::asio::steady_timer)(
71 other.pending_write_)),
72 #endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
74 BOOST_ASIO_MOVE_CAST(std::vector<unsigned char>)(
75 other.output_buffer_space_)),
76 output_buffer_(other.output_buffer_),
78 BOOST_ASIO_MOVE_CAST(std::vector<unsigned char>)(
79 other.input_buffer_space_)),
80 input_buffer_(other.input_buffer_),
83 other.output_buffer_ = boost::asio::mutable_buffer(0, 0);
84 other.input_buffer_ = boost::asio::mutable_buffer(0, 0);
85 other.input_ = boost::asio::const_buffer(0, 0);
87 #endif // defined(BOOST_ASIO_HAS_MOVE)
96 #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
97 // Timer used for storing queued read operations.
98 boost::asio::deadline_timer pending_read_;
100 // Timer used for storing queued write operations.
101 boost::asio::deadline_timer pending_write_;
103 // Helper function for obtaining a time value that always fires.
104 static boost::asio::deadline_timer::time_type neg_infin()
106 return boost::posix_time::neg_infin;
109 // Helper function for obtaining a time value that never fires.
110 static boost::asio::deadline_timer::time_type pos_infin()
112 return boost::posix_time::pos_infin;
115 // Helper function to get a timer's expiry time.
116 static boost::asio::deadline_timer::time_type expiry(
117 const boost::asio::deadline_timer& timer)
119 return timer.expires_at();
121 #else // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
122 // Timer used for storing queued read operations.
123 boost::asio::steady_timer pending_read_;
125 // Timer used for storing queued write operations.
126 boost::asio::steady_timer pending_write_;
128 // Helper function for obtaining a time value that always fires.
129 static boost::asio::steady_timer::time_point neg_infin()
131 return (boost::asio::steady_timer::time_point::min)();
134 // Helper function for obtaining a time value that never fires.
135 static boost::asio::steady_timer::time_point pos_infin()
137 return (boost::asio::steady_timer::time_point::max)();
140 // Helper function to get a timer's expiry time.
141 static boost::asio::steady_timer::time_point expiry(
142 const boost::asio::steady_timer& timer)
144 return timer.expiry();
146 #endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
148 // Buffer space used to prepare output intended for the transport.
149 std::vector<unsigned char> output_buffer_space_;
151 // A buffer that may be used to prepare output intended for the transport.
152 boost::asio::mutable_buffer output_buffer_;
154 // Buffer space used to read input intended for the engine.
155 std::vector<unsigned char> input_buffer_space_;
157 // A buffer that may be used to read input intended for the engine.
158 boost::asio::mutable_buffer input_buffer_;
160 // The buffer pointing to the engine's unconsumed input.
161 boost::asio::const_buffer input_;
164 } // namespace detail
169 #include <boost/asio/detail/pop_options.hpp>
171 #endif // BOOST_ASIO_SSL_DETAIL_STREAM_CORE_HPP