]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/asio/ssl/detail/buffered_handshake_op.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / asio / ssl / detail / buffered_handshake_op.hpp
CommitLineData
7c673cae
FG
1//
2// ssl/detail/buffered_handshake_op.hpp
3// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4//
f67539c2 5// Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7c673cae
FG
6//
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)
9//
10
11#ifndef BOOST_ASIO_SSL_DETAIL_BUFFERED_HANDSHAKE_OP_HPP
12#define BOOST_ASIO_SSL_DETAIL_BUFFERED_HANDSHAKE_OP_HPP
13
14#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15# pragma once
16#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
18#include <boost/asio/detail/config.hpp>
19
b32b8144 20#include <boost/asio/ssl/detail/engine.hpp>
7c673cae
FG
21
22#include <boost/asio/detail/push_options.hpp>
23
24namespace boost {
25namespace asio {
26namespace ssl {
27namespace detail {
28
7c673cae
FG
29template <typename ConstBufferSequence>
30class buffered_handshake_op
31{
32public:
20effc67
TL
33 static BOOST_ASIO_CONSTEXPR const char* tracking_name()
34 {
35 return "ssl::stream<>::async_buffered_handshake";
36 }
37
7c673cae
FG
38 buffered_handshake_op(stream_base::handshake_type type,
39 const ConstBufferSequence& buffers)
40 : type_(type),
41 buffers_(buffers),
42 total_buffer_size_(boost::asio::buffer_size(buffers_))
43 {
44 }
45
46 engine::want operator()(engine& eng,
47 boost::system::error_code& ec,
48 std::size_t& bytes_transferred) const
49 {
b32b8144
FG
50 return this->process(eng, ec, bytes_transferred,
51 boost::asio::buffer_sequence_begin(buffers_),
52 boost::asio::buffer_sequence_end(buffers_));
53 }
54
55 template <typename Handler>
56 void call_handler(Handler& handler,
57 const boost::system::error_code& ec,
58 const std::size_t& bytes_transferred) const
59 {
60 handler(ec, bytes_transferred);
61 }
62
63private:
64 template <typename Iterator>
65 engine::want process(engine& eng,
66 boost::system::error_code& ec,
67 std::size_t& bytes_transferred,
68 Iterator begin, Iterator end) const
69 {
70 Iterator iter = begin;
7c673cae
FG
71 std::size_t accumulated_size = 0;
72
73 for (;;)
74 {
75 engine::want want = eng.handshake(type_, ec);
76 if (want != engine::want_input_and_retry
77 || bytes_transferred == total_buffer_size_)
78 return want;
79
80 // Find the next buffer piece to be fed to the engine.
81 while (iter != end)
82 {
83 const_buffer buffer(*iter);
84
85 // Skip over any buffers which have already been consumed by the engine.
b32b8144 86 if (bytes_transferred >= accumulated_size + buffer.size())
7c673cae 87 {
b32b8144 88 accumulated_size += buffer.size();
7c673cae
FG
89 ++iter;
90 continue;
91 }
92
93 // The current buffer may have been partially consumed by the engine on
94 // a previous iteration. If so, adjust the buffer to point to the
95 // unused portion.
96 if (bytes_transferred > accumulated_size)
97 buffer = buffer + (bytes_transferred - accumulated_size);
98
99 // Pass the buffer to the engine, and update the bytes transferred to
100 // reflect the total number of bytes consumed so far.
b32b8144 101 bytes_transferred += buffer.size();
7c673cae 102 buffer = eng.put_input(buffer);
b32b8144 103 bytes_transferred -= buffer.size();
7c673cae
FG
104 break;
105 }
106 }
107 }
108
7c673cae
FG
109 stream_base::handshake_type type_;
110 ConstBufferSequence buffers_;
111 std::size_t total_buffer_size_;
112};
113
7c673cae
FG
114} // namespace detail
115} // namespace ssl
116} // namespace asio
117} // namespace boost
118
119#include <boost/asio/detail/pop_options.hpp>
120
121#endif // BOOST_ASIO_SSL_DETAIL_BUFFERED_HANDSHAKE_OP_HPP