Realistic 3D camera system
3D camera system components
buffered_handshake_op.hpp
Go to the documentation of this file.
1 //
2 // ssl/detail/buffered_handshake_op.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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 ASIO_SSL_DETAIL_BUFFERED_HANDSHAKE_OP_HPP
12 #define 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 "asio/detail/config.hpp"
19 
20 #if !defined(ASIO_ENABLE_OLD_SSL)
22 #endif // !defined(ASIO_ENABLE_OLD_SSL)
23 
25 
26 namespace asio {
27 namespace ssl {
28 namespace detail {
29 
30 #if !defined(ASIO_ENABLE_OLD_SSL)
31 
32 template <typename ConstBufferSequence>
34 {
35 public:
37  const ConstBufferSequence& buffers)
38  : type_(type),
39  buffers_(buffers),
40  total_buffer_size_(asio::buffer_size(buffers_))
41  {
42  }
43 
45  asio::error_code& ec,
46  std::size_t& bytes_transferred) const
47  {
48  typename ConstBufferSequence::const_iterator iter = buffers_.begin();
49  typename ConstBufferSequence::const_iterator end = buffers_.end();
50  std::size_t accumulated_size = 0;
51 
52  for (;;)
53  {
54  engine::want want = eng.handshake(type_, ec);
56  || bytes_transferred == total_buffer_size_)
57  return want;
58 
59  // Find the next buffer piece to be fed to the engine.
60  while (iter != end)
61  {
62  const_buffer buffer(*iter);
63 
64  // Skip over any buffers which have already been consumed by the engine.
65  if (bytes_transferred >= accumulated_size + buffer_size(buffer))
66  {
67  accumulated_size += buffer_size(buffer);
68  ++iter;
69  continue;
70  }
71 
72  // The current buffer may have been partially consumed by the engine on
73  // a previous iteration. If so, adjust the buffer to point to the
74  // unused portion.
75  if (bytes_transferred > accumulated_size)
76  buffer = buffer + (bytes_transferred - accumulated_size);
77 
78  // Pass the buffer to the engine, and update the bytes transferred to
79  // reflect the total number of bytes consumed so far.
80  bytes_transferred += buffer_size(buffer);
81  buffer = eng.put_input(buffer);
82  bytes_transferred -= buffer_size(buffer);
83  break;
84  }
85  }
86  }
87 
88  template <typename Handler>
89  void call_handler(Handler& handler,
90  const asio::error_code& ec,
91  const std::size_t& bytes_transferred) const
92  {
93  handler(ec, bytes_transferred);
94  }
95 
96 private:
98  ConstBufferSequence buffers_;
99  std::size_t total_buffer_size_;
100 };
101 
102 #endif // !defined(ASIO_ENABLE_OLD_SSL)
103 
104 } // namespace detail
105 } // namespace ssl
106 } // namespace asio
107 
109 
110 #endif // ASIO_SSL_DETAIL_BUFFERED_HANDSHAKE_OP_HPP
Holds a buffer that cannot be modified.
Definition: buffer.hpp:211
ASIO_DECL want handshake(stream_base::handshake_type type, asio::error_code &ec)
Definition: engine.ipp:133
mutable_buffers_1 buffer(const mutable_buffer &b)
Create a new modifiable buffer from an existing buffer.
Definition: buffer.hpp:706
buffered_handshake_op(stream_base::handshake_type type, const ConstBufferSequence &buffers)
std::size_t buffer_size(const mutable_buffer &b)
Get the number of bytes in a modifiable buffer.
Definition: buffer.hpp:357
handshake_type
Different handshake types.
Definition: stream_base.hpp:31
const MutableBufferSequence & buffers
Definition: read.hpp:521
Class to represent an error code value.
Definition: error_code.hpp:80
engine::want operator()(engine &eng, asio::error_code &ec, std::size_t &bytes_transferred) const
void call_handler(Handler &handler, const asio::error_code &ec, const std::size_t &bytes_transferred) const
ASIO_DECL asio::const_buffer put_input(const asio::const_buffer &data)
Definition: engine.ipp:184
SocketService Iterator Iterator end
Definition: connect.hpp:592