~ai.tron/armagetronad/0.4-winlibs-updated

« back to all changes in this revision

Viewing changes to boost/includes/boost/asio/ssl/detail/buffered_handshake_op.hpp

  • Committer: Nik K.
  • Date: 2013-11-07 16:58:35 UTC
  • Revision ID: nik.karbaum@gmail.com-20131107165835-kq99jz23drfj4dkh
Forgot to add some files; here they are

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// ssl/detail/buffered_handshake_op.hpp
 
3
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
4
//
 
5
// Copyright (c) 2003-2013 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 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
 
 
20
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
 
21
# include <boost/asio/ssl/detail/engine.hpp>
 
22
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
 
23
 
 
24
#include <boost/asio/detail/push_options.hpp>
 
25
 
 
26
namespace boost {
 
27
namespace asio {
 
28
namespace ssl {
 
29
namespace detail {
 
30
 
 
31
#if !defined(BOOST_ASIO_ENABLE_OLD_SSL)
 
32
 
 
33
template <typename ConstBufferSequence>
 
34
class buffered_handshake_op
 
35
{
 
36
public:
 
37
  buffered_handshake_op(stream_base::handshake_type type,
 
38
      const ConstBufferSequence& buffers)
 
39
    : type_(type),
 
40
      buffers_(buffers),
 
41
      total_buffer_size_(boost::asio::buffer_size(buffers_))
 
42
  {
 
43
  }
 
44
 
 
45
  engine::want operator()(engine& eng,
 
46
      boost::system::error_code& ec,
 
47
      std::size_t& bytes_transferred) const
 
48
  {
 
49
    typename ConstBufferSequence::const_iterator iter = buffers_.begin();
 
50
    typename ConstBufferSequence::const_iterator end = buffers_.end();
 
51
    std::size_t accumulated_size = 0;
 
52
 
 
53
    for (;;)
 
54
    {
 
55
      engine::want want = eng.handshake(type_, ec);
 
56
      if (want != engine::want_input_and_retry
 
57
          || bytes_transferred == total_buffer_size_)
 
58
        return want;
 
59
 
 
60
      // Find the next buffer piece to be fed to the engine.
 
61
      while (iter != end)
 
62
      {
 
63
        const_buffer buffer(*iter);
 
64
 
 
65
        // Skip over any buffers which have already been consumed by the engine.
 
66
        if (bytes_transferred >= accumulated_size + buffer_size(buffer))
 
67
        {
 
68
          accumulated_size += buffer_size(buffer);
 
69
          ++iter;
 
70
          continue;
 
71
        }
 
72
 
 
73
        // The current buffer may have been partially consumed by the engine on
 
74
        // a previous iteration. If so, adjust the buffer to point to the
 
75
        // unused portion.
 
76
        if (bytes_transferred > accumulated_size)
 
77
          buffer = buffer + (bytes_transferred - accumulated_size);
 
78
 
 
79
        // Pass the buffer to the engine, and update the bytes transferred to
 
80
        // reflect the total number of bytes consumed so far.
 
81
        bytes_transferred += buffer_size(buffer);
 
82
        buffer = eng.put_input(buffer);
 
83
        bytes_transferred -= buffer_size(buffer);
 
84
        break;
 
85
      }
 
86
    }
 
87
  }
 
88
 
 
89
  template <typename Handler>
 
90
  void call_handler(Handler& handler,
 
91
      const boost::system::error_code& ec,
 
92
      const std::size_t& bytes_transferred) const
 
93
  {
 
94
    handler(ec, bytes_transferred);
 
95
  }
 
96
 
 
97
private:
 
98
  stream_base::handshake_type type_;
 
99
  ConstBufferSequence buffers_;
 
100
  std::size_t total_buffer_size_;
 
101
};
 
102
 
 
103
#endif // !defined(BOOST_ASIO_ENABLE_OLD_SSL)
 
104
 
 
105
} // namespace detail
 
106
} // namespace ssl
 
107
} // namespace asio
 
108
} // namespace boost
 
109
 
 
110
#include <boost/asio/detail/pop_options.hpp>
 
111
 
 
112
#endif // BOOST_ASIO_SSL_DETAIL_BUFFERED_HANDSHAKE_OP_HPP