10#ifndef BOOST_BEAST_EXAMPLE_COMMON_SSL_STREAM_HPP
11#define BOOST_BEAST_EXAMPLE_COMMON_SSL_STREAM_HPP
14#include <boost/beast/websocket/ssl.hpp>
16#include <boost/asio/ip/tcp.hpp>
17#include <boost/asio/ssl/stream.hpp>
37template<
class NextLayer>
39 :
public boost::asio::ssl::stream_base
41 using stream_type = boost::asio::ssl::stream<NextLayer>;
43 std::unique_ptr<stream_type> p_;
44 boost::asio::ssl::context* ctx_;
48 using native_handle_type =
typename stream_type::native_handle_type;
51 using impl_struct =
typename stream_type::impl_struct;
54 using next_layer_type =
typename stream_type::next_layer_type;
57 using lowest_layer_type =
typename stream_type::lowest_layer_type;
60 using executor_type =
typename stream_type::executor_type;
65 boost::asio::ssl::context& ctx)
67 std::forward<Arg>(arg), ctx})
72 ssl_stream(ssl_stream&& other)
73 : p_(std::move(other.p_))
78 ssl_stream& operator=(ssl_stream&& other)
80 p_ = std::move(other.p_);
86 get_executor() noexcept
88 return p_->get_executor();
94 return p_->native_handle();
97 next_layer_type
const&
100 return p_->next_layer();
106 return p_->next_layer();
112 return p_->lowest_layer();
115 lowest_layer_type
const&
118 return p_->lowest_layer();
122 set_verify_mode(boost::asio::ssl::verify_mode v)
124 p_->set_verify_mode(v);
127 boost::system::error_code
128 set_verify_mode(boost::asio::ssl::verify_mode v,
129 boost::system::error_code& ec)
131 return p_->set_verify_mode(v, ec);
135 set_verify_depth(
int depth)
137 p_->set_verify_depth(depth);
140 boost::system::error_code
142 int depth, boost::system::error_code& ec)
144 return p_->set_verify_depth(depth, ec);
147 template<
class VerifyCallback>
149 set_verify_callback(VerifyCallback callback)
151 p_->set_verify_callback(callback);
154 template<
class VerifyCallback>
155 boost::system::error_code
156 set_verify_callback(VerifyCallback callback,
157 boost::system::error_code& ec)
159 return p_->set_verify_callback(callback, ec);
163 handshake(handshake_type type)
168 boost::system::error_code
169 handshake(handshake_type type,
170 boost::system::error_code& ec)
172 return p_->handshake(type, ec);
175 template<
class ConstBufferSequence>
178 handshake_type type, ConstBufferSequence
const& buffers)
180 p_->handshake(type, buffers);
183 template<
class ConstBufferSequence>
184 boost::system::error_code
185 handshake(handshake_type type,
186 ConstBufferSequence
const& buffers,
187 boost::system::error_code& ec)
189 return p_->handshake(type, buffers, ec);
192 template<
class HandshakeHandler>
193 BOOST_ASIO_INITFN_RESULT_TYPE(HandshakeHandler,
194 void(boost::system::error_code))
195 async_handshake(handshake_type type,
196 BOOST_ASIO_MOVE_ARG(HandshakeHandler) handler)
198 return p_->async_handshake(type,
199 BOOST_ASIO_MOVE_CAST(HandshakeHandler)(handler));
202 template<
class ConstBufferSequence,
class BufferedHandshakeHandler>
203 BOOST_ASIO_INITFN_RESULT_TYPE(BufferedHandshakeHandler,
204 void (boost::system::error_code, std::size_t))
205 async_handshake(handshake_type type, ConstBufferSequence
const& buffers,
206 BOOST_ASIO_MOVE_ARG(BufferedHandshakeHandler) handler)
208 return p_->async_handshake(type, buffers,
209 BOOST_ASIO_MOVE_CAST(BufferedHandshakeHandler)(handler));
218 boost::system::error_code
219 shutdown(boost::system::error_code& ec)
221 return p_->shutdown(ec);
224 template<
class ShutdownHandler>
225 BOOST_ASIO_INITFN_RESULT_TYPE(ShutdownHandler,
226 void (boost::system::error_code))
227 async_shutdown(BOOST_ASIO_MOVE_ARG(ShutdownHandler) handler)
229 return p_->async_shutdown(
230 BOOST_ASIO_MOVE_CAST(ShutdownHandler)(handler));
233 template<
class ConstBufferSequence>
235 write_some(ConstBufferSequence
const& buffers)
237 return p_->write_some(buffers);
240 template<
class ConstBufferSequence>
242 write_some(ConstBufferSequence
const& buffers,
243 boost::system::error_code& ec)
245 return p_->write_some(buffers, ec);
248 template<
class ConstBufferSequence,
class WriteHandler>
249 BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
250 void (boost::system::error_code, std::size_t))
251 async_write_some(ConstBufferSequence
const& buffers,
252 BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
254 return p_->async_write_some(buffers,
255 BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
258 template<
class MutableBufferSequence>
260 read_some(MutableBufferSequence
const& buffers)
262 return p_->read_some(buffers);
265 template<
class MutableBufferSequence>
267 read_some(MutableBufferSequence
const& buffers,
268 boost::system::error_code& ec)
270 return p_->read_some(buffers, ec);
273 template<
class MutableBufferSequence,
class ReadHandler>
274 BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
275 void(boost::system::error_code, std::size_t))
276 async_read_some(MutableBufferSequence
const& buffers,
277 BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
279 return p_->async_read_some(buffers,
280 BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
283 template<
class SyncStream>
286 teardown(boost::beast::websocket::role_type,
287 ssl_stream<SyncStream>& stream,
288 boost::system::error_code& ec);
290 template<
class AsyncStream,
class TeardownHandler>
293 async_teardown(boost::beast::websocket::role_type,
294 ssl_stream<AsyncStream>& stream, TeardownHandler&& handler);
301template<
class SyncStream>
305 boost::beast::websocket::role_type role,
306 ssl_stream<SyncStream>& stream,
307 boost::system::error_code& ec)
310 using boost::beast::websocket::teardown;
311 teardown(role, *stream.p_, ec);
314template<
class AsyncStream,
class TeardownHandler>
318 boost::beast::websocket::role_type role,
319 ssl_stream<AsyncStream>& stream,
320 TeardownHandler&& handler)
323 using boost::beast::websocket::async_teardown;
325 *stream.p_, std::forward<TeardownHandler>(handler));