Chris@16
|
1 //
|
Chris@16
|
2 // ssl/old/stream_service.hpp
|
Chris@16
|
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
Chris@16
|
4 //
|
Chris@16
|
5 // Copyright (c) 2005 Voipster / Indrek dot Juhani at voipster dot com
|
Chris@101
|
6 // Copyright (c) 2005-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
Chris@16
|
7 //
|
Chris@16
|
8 // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
9 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
10 //
|
Chris@16
|
11
|
Chris@16
|
12 #ifndef BOOST_ASIO_SSL_OLD_STREAM_SERVICE_HPP
|
Chris@16
|
13 #define BOOST_ASIO_SSL_OLD_STREAM_SERVICE_HPP
|
Chris@16
|
14
|
Chris@16
|
15 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
Chris@16
|
16 # pragma once
|
Chris@16
|
17 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
Chris@16
|
18
|
Chris@16
|
19 #include <boost/asio/detail/config.hpp>
|
Chris@16
|
20 #include <cstddef>
|
Chris@16
|
21 #include <boost/noncopyable.hpp>
|
Chris@16
|
22 #include <boost/asio/io_service.hpp>
|
Chris@16
|
23 #include <boost/asio/ssl/basic_context.hpp>
|
Chris@16
|
24 #include <boost/asio/ssl/old/detail/openssl_stream_service.hpp>
|
Chris@16
|
25 #include <boost/asio/ssl/stream_base.hpp>
|
Chris@16
|
26
|
Chris@16
|
27 #include <boost/asio/detail/push_options.hpp>
|
Chris@16
|
28
|
Chris@16
|
29 namespace boost {
|
Chris@16
|
30 namespace asio {
|
Chris@16
|
31 namespace ssl {
|
Chris@16
|
32 namespace old {
|
Chris@16
|
33
|
Chris@16
|
34 /// Default service implementation for an SSL stream.
|
Chris@16
|
35 class stream_service
|
Chris@16
|
36 #if defined(GENERATING_DOCUMENTATION)
|
Chris@16
|
37 : public boost::asio::io_service::service
|
Chris@16
|
38 #else
|
Chris@16
|
39 : public boost::asio::detail::service_base<stream_service>
|
Chris@16
|
40 #endif
|
Chris@16
|
41 {
|
Chris@16
|
42 private:
|
Chris@16
|
43 // The type of the platform-specific implementation.
|
Chris@16
|
44 typedef old::detail::openssl_stream_service service_impl_type;
|
Chris@16
|
45
|
Chris@16
|
46 public:
|
Chris@16
|
47 #if defined(GENERATING_DOCUMENTATION)
|
Chris@16
|
48 /// The unique service identifier.
|
Chris@16
|
49 static boost::asio::io_service::id id;
|
Chris@16
|
50 #endif
|
Chris@16
|
51
|
Chris@16
|
52 /// The type of a stream implementation.
|
Chris@16
|
53 #if defined(GENERATING_DOCUMENTATION)
|
Chris@16
|
54 typedef implementation_defined impl_type;
|
Chris@16
|
55 #else
|
Chris@16
|
56 typedef service_impl_type::impl_type impl_type;
|
Chris@16
|
57 #endif
|
Chris@16
|
58
|
Chris@16
|
59 /// Construct a new stream service for the specified io_service.
|
Chris@16
|
60 explicit stream_service(boost::asio::io_service& io_service)
|
Chris@16
|
61 : boost::asio::detail::service_base<stream_service>(io_service),
|
Chris@16
|
62 service_impl_(boost::asio::use_service<service_impl_type>(io_service))
|
Chris@16
|
63 {
|
Chris@16
|
64 }
|
Chris@16
|
65
|
Chris@16
|
66 /// Return a null stream implementation.
|
Chris@16
|
67 impl_type null() const
|
Chris@16
|
68 {
|
Chris@16
|
69 return service_impl_.null();
|
Chris@16
|
70 }
|
Chris@16
|
71
|
Chris@16
|
72 /// Create a new stream implementation.
|
Chris@16
|
73 template <typename Stream, typename Context_Service>
|
Chris@16
|
74 void create(impl_type& impl, Stream& next_layer,
|
Chris@16
|
75 basic_context<Context_Service>& context)
|
Chris@16
|
76 {
|
Chris@16
|
77 service_impl_.create(impl, next_layer, context);
|
Chris@16
|
78 }
|
Chris@16
|
79
|
Chris@16
|
80 /// Destroy a stream implementation.
|
Chris@16
|
81 template <typename Stream>
|
Chris@16
|
82 void destroy(impl_type& impl, Stream& next_layer)
|
Chris@16
|
83 {
|
Chris@16
|
84 service_impl_.destroy(impl, next_layer);
|
Chris@16
|
85 }
|
Chris@16
|
86
|
Chris@16
|
87 /// Perform SSL handshaking.
|
Chris@16
|
88 template <typename Stream>
|
Chris@16
|
89 boost::system::error_code handshake(impl_type& impl, Stream& next_layer,
|
Chris@16
|
90 stream_base::handshake_type type, boost::system::error_code& ec)
|
Chris@16
|
91 {
|
Chris@16
|
92 return service_impl_.handshake(impl, next_layer, type, ec);
|
Chris@16
|
93 }
|
Chris@16
|
94
|
Chris@16
|
95 /// Start an asynchronous SSL handshake.
|
Chris@16
|
96 template <typename Stream, typename HandshakeHandler>
|
Chris@16
|
97 void async_handshake(impl_type& impl, Stream& next_layer,
|
Chris@16
|
98 stream_base::handshake_type type, HandshakeHandler handler)
|
Chris@16
|
99 {
|
Chris@16
|
100 service_impl_.async_handshake(impl, next_layer, type, handler);
|
Chris@16
|
101 }
|
Chris@16
|
102
|
Chris@16
|
103 /// Shut down SSL on the stream.
|
Chris@16
|
104 template <typename Stream>
|
Chris@16
|
105 boost::system::error_code shutdown(impl_type& impl, Stream& next_layer,
|
Chris@16
|
106 boost::system::error_code& ec)
|
Chris@16
|
107 {
|
Chris@16
|
108 return service_impl_.shutdown(impl, next_layer, ec);
|
Chris@16
|
109 }
|
Chris@16
|
110
|
Chris@16
|
111 /// Asynchronously shut down SSL on the stream.
|
Chris@16
|
112 template <typename Stream, typename ShutdownHandler>
|
Chris@16
|
113 void async_shutdown(impl_type& impl, Stream& next_layer,
|
Chris@16
|
114 ShutdownHandler handler)
|
Chris@16
|
115 {
|
Chris@16
|
116 service_impl_.async_shutdown(impl, next_layer, handler);
|
Chris@16
|
117 }
|
Chris@16
|
118
|
Chris@16
|
119 /// Write some data to the stream.
|
Chris@16
|
120 template <typename Stream, typename ConstBufferSequence>
|
Chris@16
|
121 std::size_t write_some(impl_type& impl, Stream& next_layer,
|
Chris@16
|
122 const ConstBufferSequence& buffers, boost::system::error_code& ec)
|
Chris@16
|
123 {
|
Chris@16
|
124 return service_impl_.write_some(impl, next_layer, buffers, ec);
|
Chris@16
|
125 }
|
Chris@16
|
126
|
Chris@16
|
127 /// Start an asynchronous write.
|
Chris@16
|
128 template <typename Stream, typename ConstBufferSequence,
|
Chris@16
|
129 typename WriteHandler>
|
Chris@16
|
130 void async_write_some(impl_type& impl, Stream& next_layer,
|
Chris@16
|
131 const ConstBufferSequence& buffers, WriteHandler handler)
|
Chris@16
|
132 {
|
Chris@16
|
133 service_impl_.async_write_some(impl, next_layer, buffers, handler);
|
Chris@16
|
134 }
|
Chris@16
|
135
|
Chris@16
|
136 /// Read some data from the stream.
|
Chris@16
|
137 template <typename Stream, typename MutableBufferSequence>
|
Chris@16
|
138 std::size_t read_some(impl_type& impl, Stream& next_layer,
|
Chris@16
|
139 const MutableBufferSequence& buffers, boost::system::error_code& ec)
|
Chris@16
|
140 {
|
Chris@16
|
141 return service_impl_.read_some(impl, next_layer, buffers, ec);
|
Chris@16
|
142 }
|
Chris@16
|
143
|
Chris@16
|
144 /// Start an asynchronous read.
|
Chris@16
|
145 template <typename Stream, typename MutableBufferSequence,
|
Chris@16
|
146 typename ReadHandler>
|
Chris@16
|
147 void async_read_some(impl_type& impl, Stream& next_layer,
|
Chris@16
|
148 const MutableBufferSequence& buffers, ReadHandler handler)
|
Chris@16
|
149 {
|
Chris@16
|
150 service_impl_.async_read_some(impl, next_layer, buffers, handler);
|
Chris@16
|
151 }
|
Chris@16
|
152
|
Chris@16
|
153 /// Peek at the incoming data on the stream.
|
Chris@16
|
154 template <typename Stream, typename MutableBufferSequence>
|
Chris@16
|
155 std::size_t peek(impl_type& impl, Stream& next_layer,
|
Chris@16
|
156 const MutableBufferSequence& buffers, boost::system::error_code& ec)
|
Chris@16
|
157 {
|
Chris@16
|
158 return service_impl_.peek(impl, next_layer, buffers, ec);
|
Chris@16
|
159 }
|
Chris@16
|
160
|
Chris@16
|
161 /// Determine the amount of data that may be read without blocking.
|
Chris@16
|
162 template <typename Stream>
|
Chris@16
|
163 std::size_t in_avail(impl_type& impl, Stream& next_layer,
|
Chris@16
|
164 boost::system::error_code& ec)
|
Chris@16
|
165 {
|
Chris@16
|
166 return service_impl_.in_avail(impl, next_layer, ec);
|
Chris@16
|
167 }
|
Chris@16
|
168
|
Chris@16
|
169 private:
|
Chris@16
|
170 // Destroy all user-defined handler objects owned by the service.
|
Chris@16
|
171 void shutdown_service()
|
Chris@16
|
172 {
|
Chris@16
|
173 }
|
Chris@16
|
174
|
Chris@16
|
175 // The service that provides the platform-specific implementation.
|
Chris@16
|
176 service_impl_type& service_impl_;
|
Chris@16
|
177 };
|
Chris@16
|
178
|
Chris@16
|
179 } // namespace old
|
Chris@16
|
180 } // namespace ssl
|
Chris@16
|
181 } // namespace asio
|
Chris@16
|
182 } // namespace boost
|
Chris@16
|
183
|
Chris@16
|
184 #include <boost/asio/detail/pop_options.hpp>
|
Chris@16
|
185
|
Chris@16
|
186 #endif // BOOST_ASIO_SSL_OLD_STREAM_SERVICE_HPP
|