File indexing completed on 2025-01-18 09:29:01
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_SSL_DETAIL_BUFFERED_HANDSHAKE_OP_HPP
0012 #define BOOST_ASIO_SSL_DETAIL_BUFFERED_HANDSHAKE_OP_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019
0020 #include <boost/asio/ssl/detail/engine.hpp>
0021
0022 #include <boost/asio/detail/push_options.hpp>
0023
0024 namespace boost {
0025 namespace asio {
0026 namespace ssl {
0027 namespace detail {
0028
0029 template <typename ConstBufferSequence>
0030 class buffered_handshake_op
0031 {
0032 public:
0033 static constexpr const char* tracking_name()
0034 {
0035 return "ssl::stream<>::async_buffered_handshake";
0036 }
0037
0038 buffered_handshake_op(stream_base::handshake_type type,
0039 const ConstBufferSequence& buffers)
0040 : type_(type),
0041 buffers_(buffers),
0042 total_buffer_size_(boost::asio::buffer_size(buffers_))
0043 {
0044 }
0045
0046 engine::want operator()(engine& eng,
0047 boost::system::error_code& ec,
0048 std::size_t& bytes_transferred) const
0049 {
0050 return this->process(eng, ec, bytes_transferred,
0051 boost::asio::buffer_sequence_begin(buffers_),
0052 boost::asio::buffer_sequence_end(buffers_));
0053 }
0054
0055 template <typename Handler>
0056 void call_handler(Handler& handler,
0057 const boost::system::error_code& ec,
0058 const std::size_t& bytes_transferred) const
0059 {
0060 static_cast<Handler&&>(handler)(ec, bytes_transferred);
0061 }
0062
0063 private:
0064 template <typename Iterator>
0065 engine::want process(engine& eng,
0066 boost::system::error_code& ec,
0067 std::size_t& bytes_transferred,
0068 Iterator begin, Iterator end) const
0069 {
0070 Iterator iter = begin;
0071 std::size_t accumulated_size = 0;
0072
0073 for (;;)
0074 {
0075 engine::want want = eng.handshake(type_, ec);
0076 if (want != engine::want_input_and_retry
0077 || bytes_transferred == total_buffer_size_)
0078 return want;
0079
0080
0081 while (iter != end)
0082 {
0083 const_buffer buffer(*iter);
0084
0085
0086 if (bytes_transferred >= accumulated_size + buffer.size())
0087 {
0088 accumulated_size += buffer.size();
0089 ++iter;
0090 continue;
0091 }
0092
0093
0094
0095
0096 if (bytes_transferred > accumulated_size)
0097 buffer = buffer + (bytes_transferred - accumulated_size);
0098
0099
0100
0101 bytes_transferred += buffer.size();
0102 buffer = eng.put_input(buffer);
0103 bytes_transferred -= buffer.size();
0104 break;
0105 }
0106 }
0107 }
0108
0109 stream_base::handshake_type type_;
0110 ConstBufferSequence buffers_;
0111 std::size_t total_buffer_size_;
0112 };
0113
0114 }
0115 }
0116 }
0117 }
0118
0119 #include <boost/asio/detail/pop_options.hpp>
0120
0121 #endif