2 // ssl/old/stream_service.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2005 Voipster / Indrek dot Juhani at voipster dot com
6 // Copyright (c) 2005-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
8 // Distributed under the Boost Software License, Version 1.0. (See accompanying
9 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
12 #ifndef BOOST_ASIO_SSL_OLD_STREAM_SERVICE_HPP
13 #define BOOST_ASIO_SSL_OLD_STREAM_SERVICE_HPP
15 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
17 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
19 #include <boost/asio/detail/config.hpp>
21 #include <boost/noncopyable.hpp>
22 #include <boost/asio/io_service.hpp>
23 #include <boost/asio/ssl/basic_context.hpp>
24 #include <boost/asio/ssl/old/detail/openssl_stream_service.hpp>
25 #include <boost/asio/ssl/stream_base.hpp>
27 #include <boost/asio/detail/push_options.hpp>
34 /// Default service implementation for an SSL stream.
36 #if defined(GENERATING_DOCUMENTATION)
37 : public boost::asio::io_service::service
39 : public boost::asio::detail::service_base<stream_service>
43 // The type of the platform-specific implementation.
44 typedef old::detail::openssl_stream_service service_impl_type;
47 #if defined(GENERATING_DOCUMENTATION)
48 /// The unique service identifier.
49 static boost::asio::io_service::id id;
52 /// The type of a stream implementation.
53 #if defined(GENERATING_DOCUMENTATION)
54 typedef implementation_defined impl_type;
56 typedef service_impl_type::impl_type impl_type;
59 /// Construct a new stream service for the specified io_service.
60 explicit stream_service(boost::asio::io_service& io_service)
61 : boost::asio::detail::service_base<stream_service>(io_service),
62 service_impl_(boost::asio::use_service<service_impl_type>(io_service))
66 /// Return a null stream implementation.
67 impl_type null() const
69 return service_impl_.null();
72 /// Create a new stream implementation.
73 template <typename Stream, typename Context_Service>
74 void create(impl_type& impl, Stream& next_layer,
75 basic_context<Context_Service>& context)
77 service_impl_.create(impl, next_layer, context);
80 /// Destroy a stream implementation.
81 template <typename Stream>
82 void destroy(impl_type& impl, Stream& next_layer)
84 service_impl_.destroy(impl, next_layer);
87 /// Perform SSL handshaking.
88 template <typename Stream>
89 boost::system::error_code handshake(impl_type& impl, Stream& next_layer,
90 stream_base::handshake_type type, boost::system::error_code& ec)
92 return service_impl_.handshake(impl, next_layer, type, ec);
95 /// Start an asynchronous SSL handshake.
96 template <typename Stream, typename HandshakeHandler>
97 void async_handshake(impl_type& impl, Stream& next_layer,
98 stream_base::handshake_type type, HandshakeHandler handler)
100 service_impl_.async_handshake(impl, next_layer, type, handler);
103 /// Shut down SSL on the stream.
104 template <typename Stream>
105 boost::system::error_code shutdown(impl_type& impl, Stream& next_layer,
106 boost::system::error_code& ec)
108 return service_impl_.shutdown(impl, next_layer, ec);
111 /// Asynchronously shut down SSL on the stream.
112 template <typename Stream, typename ShutdownHandler>
113 void async_shutdown(impl_type& impl, Stream& next_layer,
114 ShutdownHandler handler)
116 service_impl_.async_shutdown(impl, next_layer, handler);
119 /// Write some data to the stream.
120 template <typename Stream, typename ConstBufferSequence>
121 std::size_t write_some(impl_type& impl, Stream& next_layer,
122 const ConstBufferSequence& buffers, boost::system::error_code& ec)
124 return service_impl_.write_some(impl, next_layer, buffers, ec);
127 /// Start an asynchronous write.
128 template <typename Stream, typename ConstBufferSequence,
129 typename WriteHandler>
130 void async_write_some(impl_type& impl, Stream& next_layer,
131 const ConstBufferSequence& buffers, WriteHandler handler)
133 service_impl_.async_write_some(impl, next_layer, buffers, handler);
136 /// Read some data from the stream.
137 template <typename Stream, typename MutableBufferSequence>
138 std::size_t read_some(impl_type& impl, Stream& next_layer,
139 const MutableBufferSequence& buffers, boost::system::error_code& ec)
141 return service_impl_.read_some(impl, next_layer, buffers, ec);
144 /// Start an asynchronous read.
145 template <typename Stream, typename MutableBufferSequence,
146 typename ReadHandler>
147 void async_read_some(impl_type& impl, Stream& next_layer,
148 const MutableBufferSequence& buffers, ReadHandler handler)
150 service_impl_.async_read_some(impl, next_layer, buffers, handler);
153 /// Peek at the incoming data on the stream.
154 template <typename Stream, typename MutableBufferSequence>
155 std::size_t peek(impl_type& impl, Stream& next_layer,
156 const MutableBufferSequence& buffers, boost::system::error_code& ec)
158 return service_impl_.peek(impl, next_layer, buffers, ec);
161 /// Determine the amount of data that may be read without blocking.
162 template <typename Stream>
163 std::size_t in_avail(impl_type& impl, Stream& next_layer,
164 boost::system::error_code& ec)
166 return service_impl_.in_avail(impl, next_layer, ec);
170 // Destroy all user-defined handler objects owned by the service.
171 void shutdown_service()
175 // The service that provides the platform-specific implementation.
176 service_impl_type& service_impl_;
184 #include <boost/asio/detail/pop_options.hpp>
186 #endif // BOOST_ASIO_SSL_OLD_STREAM_SERVICE_HPP