5 // Copyright (c) 2005 Voipster / Indrek dot Juhani at voipster dot com
6 // Copyright (c) 2005-2008 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_STREAM_SERVICE_HPP
13 #define BOOST_ASIO_SSL_STREAM_SERVICE_HPP
15 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
17 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
19 #include <boost/asio/detail/push_options.hpp>
21 #include <boost/asio/detail/push_options.hpp>
23 #include <boost/config.hpp>
24 #include <boost/noncopyable.hpp>
25 #include <boost/asio/detail/pop_options.hpp>
27 #include <boost/asio/io_service.hpp>
28 #include <boost/asio/detail/service_base.hpp>
29 #include <boost/asio/ssl/basic_context.hpp>
30 #include <boost/asio/ssl/stream_base.hpp>
31 #include <boost/asio/ssl/detail/openssl_stream_service.hpp>
37 /// Default service implementation for an SSL stream.
39 #if defined(GENERATING_DOCUMENTATION)
40 : public boost::asio::io_service::service
42 : public boost::asio::detail::service_base
<stream_service
>
46 // The type of the platform-specific implementation.
47 typedef detail::openssl_stream_service service_impl_type
;
50 #if defined(GENERATING_DOCUMENTATION)
51 /// The unique service identifier.
52 static boost::asio::io_service::id id
;
55 /// The type of a stream implementation.
56 #if defined(GENERATING_DOCUMENTATION)
57 typedef implementation_defined impl_type
;
59 typedef service_impl_type::impl_type impl_type
;
62 /// Construct a new stream service for the specified io_service.
63 explicit stream_service(boost::asio::io_service
& io_service
)
64 : boost::asio::detail::service_base
<stream_service
>(io_service
),
65 service_impl_(boost::asio::use_service
<service_impl_type
>(io_service
))
69 /// Destroy all user-defined handler objects owned by the service.
70 void shutdown_service()
74 /// Return a null stream implementation.
75 impl_type
null() const
77 return service_impl_
.null();
80 /// Create a new stream implementation.
81 template <typename Stream
, typename Context_Service
>
82 void create(impl_type
& impl
, Stream
& next_layer
,
83 basic_context
<Context_Service
>& context
)
85 service_impl_
.create(impl
, next_layer
, context
);
88 /// Destroy a stream implementation.
89 template <typename Stream
>
90 void destroy(impl_type
& impl
, Stream
& next_layer
)
92 service_impl_
.destroy(impl
, next_layer
);
95 /// Perform SSL handshaking.
96 template <typename Stream
>
97 boost::system::error_code
handshake(impl_type
& impl
, Stream
& next_layer
,
98 stream_base::handshake_type type
, boost::system::error_code
& ec
)
100 return service_impl_
.handshake(impl
, next_layer
, type
, ec
);
103 /// Start an asynchronous SSL handshake.
104 template <typename Stream
, typename HandshakeHandler
>
105 void async_handshake(impl_type
& impl
, Stream
& next_layer
,
106 stream_base::handshake_type type
, HandshakeHandler handler
)
108 service_impl_
.async_handshake(impl
, next_layer
, type
, handler
);
111 /// Shut down SSL on the stream.
112 template <typename Stream
>
113 boost::system::error_code
shutdown(impl_type
& impl
, Stream
& next_layer
,
114 boost::system::error_code
& ec
)
116 return service_impl_
.shutdown(impl
, next_layer
, ec
);
119 /// Asynchronously shut down SSL on the stream.
120 template <typename Stream
, typename ShutdownHandler
>
121 void async_shutdown(impl_type
& impl
, Stream
& next_layer
,
122 ShutdownHandler handler
)
124 service_impl_
.async_shutdown(impl
, next_layer
, handler
);
127 /// Write some data to the stream.
128 template <typename Stream
, typename ConstBufferSequence
>
129 std::size_t write_some(impl_type
& impl
, Stream
& next_layer
,
130 const ConstBufferSequence
& buffers
, boost::system::error_code
& ec
)
132 return service_impl_
.write_some(impl
, next_layer
, buffers
, ec
);
135 /// Start an asynchronous write.
136 template <typename Stream
, typename ConstBufferSequence
,
137 typename WriteHandler
>
138 void async_write_some(impl_type
& impl
, Stream
& next_layer
,
139 const ConstBufferSequence
& buffers
, WriteHandler handler
)
141 service_impl_
.async_write_some(impl
, next_layer
, buffers
, handler
);
144 /// Read some data from the stream.
145 template <typename Stream
, typename MutableBufferSequence
>
146 std::size_t read_some(impl_type
& impl
, Stream
& next_layer
,
147 const MutableBufferSequence
& buffers
, boost::system::error_code
& ec
)
149 return service_impl_
.read_some(impl
, next_layer
, buffers
, ec
);
152 /// Start an asynchronous read.
153 template <typename Stream
, typename MutableBufferSequence
,
154 typename ReadHandler
>
155 void async_read_some(impl_type
& impl
, Stream
& next_layer
,
156 const MutableBufferSequence
& buffers
, ReadHandler handler
)
158 service_impl_
.async_read_some(impl
, next_layer
, buffers
, handler
);
161 /// Peek at the incoming data on the stream.
162 template <typename Stream
, typename MutableBufferSequence
>
163 std::size_t peek(impl_type
& impl
, Stream
& next_layer
,
164 const MutableBufferSequence
& buffers
, boost::system::error_code
& ec
)
166 return service_impl_
.peek(impl
, next_layer
, buffers
, ec
);
169 /// Determine the amount of data that may be read without blocking.
170 template <typename Stream
>
171 std::size_t in_avail(impl_type
& impl
, Stream
& next_layer
,
172 boost::system::error_code
& ec
)
174 return service_impl_
.in_avail(impl
, next_layer
, ec
);
178 // The service that provides the platform-specific implementation.
179 service_impl_type
& service_impl_
;
186 #include <boost/asio/detail/pop_options.hpp>
188 #endif // BOOST_ASIO_SSL_STREAM_SERVICE_HPP