ssl_stream.hpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. //
  2. // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/beast
  8. //
  9. #ifndef BOOST_BEAST_CORE_SSL_STREAM_HPP
  10. #define BOOST_BEAST_CORE_SSL_STREAM_HPP
  11. #include <boost/beast/core/detail/config.hpp>
  12. // This include is necessary to work with `ssl::stream` and `boost::beast::websocket::stream`
  13. #include <boost/beast/websocket/ssl.hpp>
  14. #include <boost/beast/core/flat_stream.hpp>
  15. // VFALCO We include this because anyone who uses ssl will
  16. // very likely need to check for ssl::error::stream_truncated
  17. #include <boost/asio/ssl/error.hpp>
  18. #include <boost/asio/ssl/stream.hpp>
  19. #include <cstddef>
  20. #include <memory>
  21. #include <type_traits>
  22. #include <utility>
  23. namespace boost {
  24. namespace beast {
  25. /** Provides stream-oriented functionality using OpenSSL
  26. The stream class template provides asynchronous and blocking
  27. stream-oriented functionality using SSL.
  28. @par Thread Safety
  29. @e Distinct @e objects: Safe.@n
  30. @e Shared @e objects: Unsafe. The application must also ensure that all
  31. asynchronous operations are performed within the same implicit or explicit
  32. strand.
  33. @par Example
  34. To use this template with a @ref tcp_stream, you would write:
  35. @code
  36. net::io_context ioc;
  37. net::ssl::context ctx{net::ssl::context::tlsv12};
  38. beast::ssl_stream<beast::tcp_stream> sock{ioc, ctx};
  39. @endcode
  40. In addition to providing an interface identical to `net::ssl::stream`,
  41. the wrapper has the following additional properties:
  42. @li Satisfies @b MoveConstructible
  43. @li Satisfies @b MoveAssignable
  44. @li Constructible from a moved socket.
  45. @li Uses @ref flat_stream internally, as a performance work-around for a
  46. limitation of `net::ssl::stream` when writing buffer sequences
  47. having length greater than one.
  48. @par Concepts:
  49. @li AsyncReadStream
  50. @li AsyncWriteStream
  51. @li Stream
  52. @li SyncReadStream
  53. @li SyncWriteStream
  54. */
  55. template<class NextLayer>
  56. class ssl_stream
  57. : public net::ssl::stream_base
  58. {
  59. using ssl_stream_type = net::ssl::stream<NextLayer>;
  60. using stream_type = boost::beast::flat_stream<ssl_stream_type>;
  61. std::unique_ptr<stream_type> p_;
  62. public:
  63. /// The native handle type of the SSL stream.
  64. using native_handle_type =
  65. typename ssl_stream_type::native_handle_type;
  66. /// Structure for use with deprecated impl_type.
  67. using impl_struct = typename ssl_stream_type::impl_struct;
  68. /// The type of the next layer.
  69. using next_layer_type = typename ssl_stream_type::next_layer_type;
  70. /// The type of the executor associated with the object.
  71. using executor_type = typename stream_type::executor_type;
  72. /// Rebinds the stream type to another executor.
  73. template<class Executor1>
  74. struct rebind_executor
  75. {
  76. /// The stream type when rebound to the specified executor.
  77. using other = ssl_stream<
  78. typename stream_type::template rebind_executor<Executor1>::other
  79. >;
  80. };
  81. /** Construct a stream.
  82. This constructor creates a stream and initialises the underlying stream
  83. object.
  84. @param arg The argument to be passed to initialise the underlying stream.
  85. @param ctx The SSL context to be used for the stream.
  86. */
  87. template<class Arg>
  88. ssl_stream(
  89. Arg&& arg,
  90. net::ssl::context& ctx)
  91. : p_(new stream_type{
  92. std::forward<Arg>(arg), ctx})
  93. {
  94. }
  95. /** Get the executor associated with the object.
  96. This function may be used to obtain the executor object that the stream
  97. uses to dispatch handlers for asynchronous operations.
  98. @return A copy of the executor that stream will use to dispatch handlers.
  99. */
  100. executor_type
  101. get_executor() noexcept
  102. {
  103. return p_->get_executor();
  104. }
  105. /** Get the underlying implementation in the native type.
  106. This function may be used to obtain the underlying implementation of the
  107. context. This is intended to allow access to context functionality that is
  108. not otherwise provided.
  109. @par Example
  110. The native_handle() function returns a pointer of type @c SSL* that is
  111. suitable for passing to functions such as @c SSL_get_verify_result and
  112. @c SSL_get_peer_certificate:
  113. @code
  114. boost::beast::ssl_stream<net::ip::tcp::socket> ss{ioc, ctx};
  115. // ... establish connection and perform handshake ...
  116. if (X509* cert = SSL_get_peer_certificate(ss.native_handle()))
  117. {
  118. if (SSL_get_verify_result(ss.native_handle()) == X509_V_OK)
  119. {
  120. // ...
  121. }
  122. }
  123. @endcode
  124. */
  125. native_handle_type
  126. native_handle() noexcept
  127. {
  128. return p_->next_layer().native_handle();
  129. }
  130. /** Get a reference to the next layer.
  131. This function returns a reference to the next layer in a stack of stream
  132. layers.
  133. @note The next layer is the wrapped stream and not the @ref flat_stream
  134. used in the implementation.
  135. @return A reference to the next layer in the stack of stream layers.
  136. Ownership is not transferred to the caller.
  137. */
  138. next_layer_type const&
  139. next_layer() const noexcept
  140. {
  141. return p_->next_layer().next_layer();
  142. }
  143. /** Get a reference to the next layer.
  144. This function returns a reference to the next layer in a stack of stream
  145. layers.
  146. @note The next layer is the wrapped stream and not the @ref flat_stream
  147. used in the implementation.
  148. @return A reference to the next layer in the stack of stream layers.
  149. Ownership is not transferred to the caller.
  150. */
  151. next_layer_type&
  152. next_layer() noexcept
  153. {
  154. return p_->next_layer().next_layer();
  155. }
  156. /** Set the peer verification mode.
  157. This function may be used to configure the peer verification mode used by
  158. the stream. The new mode will override the mode inherited from the context.
  159. @param v A bitmask of peer verification modes.
  160. @throws boost::system::system_error Thrown on failure.
  161. @note Calls @c SSL_set_verify.
  162. */
  163. void
  164. set_verify_mode(net::ssl::verify_mode v)
  165. {
  166. p_->next_layer().set_verify_mode(v);
  167. }
  168. /** Set the peer verification mode.
  169. This function may be used to configure the peer verification mode used by
  170. the stream. The new mode will override the mode inherited from the context.
  171. @param v A bitmask of peer verification modes. See `verify_mode` for
  172. available values.
  173. @param ec Set to indicate what error occurred, if any.
  174. @note Calls @c SSL_set_verify.
  175. */
  176. void
  177. set_verify_mode(net::ssl::verify_mode v,
  178. boost::system::error_code& ec)
  179. {
  180. p_->next_layer().set_verify_mode(v, ec);
  181. }
  182. /** Set the peer verification depth.
  183. This function may be used to configure the maximum verification depth
  184. allowed by the stream.
  185. @param depth Maximum depth for the certificate chain verification that
  186. shall be allowed.
  187. @throws boost::system::system_error Thrown on failure.
  188. @note Calls @c SSL_set_verify_depth.
  189. */
  190. void
  191. set_verify_depth(int depth)
  192. {
  193. p_->next_layer().set_verify_depth(depth);
  194. }
  195. /** Set the peer verification depth.
  196. This function may be used to configure the maximum verification depth
  197. allowed by the stream.
  198. @param depth Maximum depth for the certificate chain verification that
  199. shall be allowed.
  200. @param ec Set to indicate what error occurred, if any.
  201. @note Calls @c SSL_set_verify_depth.
  202. */
  203. void
  204. set_verify_depth(
  205. int depth, boost::system::error_code& ec)
  206. {
  207. p_->next_layer().set_verify_depth(depth, ec);
  208. }
  209. /** Set the callback used to verify peer certificates.
  210. This function is used to specify a callback function that will be called
  211. by the implementation when it needs to verify a peer certificate.
  212. @param callback The function object to be used for verifying a certificate.
  213. The function signature of the handler must be:
  214. @code bool verify_callback(
  215. bool preverified, // True if the certificate passed pre-verification.
  216. verify_context& ctx // The peer certificate and other context.
  217. ); @endcode
  218. The return value of the callback is true if the certificate has passed
  219. verification, false otherwise.
  220. @throws boost::system::system_error Thrown on failure.
  221. @note Calls @c SSL_set_verify.
  222. */
  223. template<class VerifyCallback>
  224. void
  225. set_verify_callback(VerifyCallback callback)
  226. {
  227. p_->next_layer().set_verify_callback(callback);
  228. }
  229. /** Set the callback used to verify peer certificates.
  230. This function is used to specify a callback function that will be called
  231. by the implementation when it needs to verify a peer certificate.
  232. @param callback The function object to be used for verifying a certificate.
  233. The function signature of the handler must be:
  234. @code bool verify_callback(
  235. bool preverified, // True if the certificate passed pre-verification.
  236. net::verify_context& ctx // The peer certificate and other context.
  237. ); @endcode
  238. The return value of the callback is true if the certificate has passed
  239. verification, false otherwise.
  240. @param ec Set to indicate what error occurred, if any.
  241. @note Calls @c SSL_set_verify.
  242. */
  243. template<class VerifyCallback>
  244. void
  245. set_verify_callback(VerifyCallback callback,
  246. boost::system::error_code& ec)
  247. {
  248. p_->next_layer().set_verify_callback(callback, ec);
  249. }
  250. /** Perform SSL handshaking.
  251. This function is used to perform SSL handshaking on the stream. The
  252. function call will block until handshaking is complete or an error occurs.
  253. @param type The type of handshaking to be performed, i.e. as a client or as
  254. a server.
  255. @throws boost::system::system_error Thrown on failure.
  256. */
  257. void
  258. handshake(handshake_type type)
  259. {
  260. p_->next_layer().handshake(type);
  261. }
  262. /** Perform SSL handshaking.
  263. This function is used to perform SSL handshaking on the stream. The
  264. function call will block until handshaking is complete or an error occurs.
  265. @param type The type of handshaking to be performed, i.e. as a client or as
  266. a server.
  267. @param ec Set to indicate what error occurred, if any.
  268. */
  269. void
  270. handshake(handshake_type type,
  271. boost::system::error_code& ec)
  272. {
  273. p_->next_layer().handshake(type, ec);
  274. }
  275. /** Perform SSL handshaking.
  276. This function is used to perform SSL handshaking on the stream. The
  277. function call will block until handshaking is complete or an error occurs.
  278. @param type The type of handshaking to be performed, i.e. as a client or as
  279. a server.
  280. @param buffers The buffered data to be reused for the handshake.
  281. @throws boost::system::system_error Thrown on failure.
  282. */
  283. template<class ConstBufferSequence>
  284. void
  285. handshake(
  286. handshake_type type, ConstBufferSequence const& buffers)
  287. {
  288. p_->next_layer().handshake(type, buffers);
  289. }
  290. /** Perform SSL handshaking.
  291. This function is used to perform SSL handshaking on the stream. The
  292. function call will block until handshaking is complete or an error occurs.
  293. @param type The type of handshaking to be performed, i.e. as a client or as
  294. a server.
  295. @param buffers The buffered data to be reused for the handshake.
  296. @param ec Set to indicate what error occurred, if any.
  297. */
  298. template<class ConstBufferSequence>
  299. void
  300. handshake(handshake_type type,
  301. ConstBufferSequence const& buffers,
  302. boost::system::error_code& ec)
  303. {
  304. p_->next_layer().handshake(type, buffers, ec);
  305. }
  306. /** Start an asynchronous SSL handshake.
  307. This function is used to asynchronously perform an SSL handshake on the
  308. stream. This function call always returns immediately.
  309. @param type The type of handshaking to be performed, i.e. as a client or as
  310. a server.
  311. @param handler The handler to be called when the handshake operation
  312. completes. Copies will be made of the handler as required. The equivalent
  313. function signature of the handler must be:
  314. @code void handler(
  315. const boost::system::error_code& error // Result of operation.
  316. ); @endcode
  317. */
  318. template<BOOST_BEAST_ASYNC_TPARAM1 HandshakeHandler = net::default_completion_token_t<executor_type>>
  319. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(HandshakeHandler, void(boost::system::error_code))
  320. async_handshake(handshake_type type,
  321. BOOST_ASIO_MOVE_ARG(HandshakeHandler) handler = net::default_completion_token_t<executor_type>{})
  322. {
  323. return p_->next_layer().async_handshake(type,
  324. BOOST_ASIO_MOVE_CAST(HandshakeHandler)(handler));
  325. }
  326. /** Start an asynchronous SSL handshake.
  327. This function is used to asynchronously perform an SSL handshake on the
  328. stream. This function call always returns immediately.
  329. @param type The type of handshaking to be performed, i.e. as a client or as
  330. a server.
  331. @param buffers The buffered data to be reused for the handshake. Although
  332. the buffers object may be copied as necessary, ownership of the underlying
  333. buffers is retained by the caller, which must guarantee that they remain
  334. valid until the handler is called.
  335. @param handler The handler to be called when the handshake operation
  336. completes. Copies will be made of the handler as required. The equivalent
  337. function signature of the handler must be:
  338. @code void handler(
  339. const boost::system::error_code& error, // Result of operation.
  340. std::size_t bytes_transferred // Amount of buffers used in handshake.
  341. ); @endcode
  342. */
  343. template<class ConstBufferSequence,
  344. BOOST_BEAST_ASYNC_TPARAM2 BufferedHandshakeHandler = net::default_completion_token_t<executor_type>>
  345. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(BufferedHandshakeHandler, void(boost::system::error_code, std::size_t))
  346. async_handshake(handshake_type type, ConstBufferSequence const& buffers,
  347. BOOST_ASIO_MOVE_ARG(BufferedHandshakeHandler) handler
  348. = net::default_completion_token_t<executor_type>{})
  349. {
  350. return p_->next_layer().async_handshake(type, buffers,
  351. BOOST_ASIO_MOVE_CAST(BufferedHandshakeHandler)(handler));
  352. }
  353. /** Shut down SSL on the stream.
  354. This function is used to shut down SSL on the stream. The function call
  355. will block until SSL has been shut down or an error occurs.
  356. @throws boost::system::system_error Thrown on failure.
  357. */
  358. void
  359. shutdown()
  360. {
  361. p_->next_layer().shutdown();
  362. }
  363. /** Shut down SSL on the stream.
  364. This function is used to shut down SSL on the stream. The function call
  365. will block until SSL has been shut down or an error occurs.
  366. @param ec Set to indicate what error occurred, if any.
  367. */
  368. void
  369. shutdown(boost::system::error_code& ec)
  370. {
  371. p_->next_layer().shutdown(ec);
  372. }
  373. /** Asynchronously shut down SSL on the stream.
  374. This function is used to asynchronously shut down SSL on the stream. This
  375. function call always returns immediately.
  376. @param handler The handler to be called when the handshake operation
  377. completes. Copies will be made of the handler as required. The equivalent
  378. function signature of the handler must be:
  379. @code void handler(
  380. const boost::system::error_code& error // Result of operation.
  381. ); @endcode
  382. */
  383. template<BOOST_BEAST_ASYNC_TPARAM1 ShutdownHandler = net::default_completion_token_t<executor_type>>
  384. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ShutdownHandler, void(boost::system::error_code))
  385. async_shutdown(BOOST_ASIO_MOVE_ARG(ShutdownHandler) handler = net::default_completion_token_t<executor_type>{})
  386. {
  387. return p_->next_layer().async_shutdown(
  388. BOOST_ASIO_MOVE_CAST(ShutdownHandler)(handler));
  389. }
  390. /** Write some data to the stream.
  391. This function is used to write data on the stream. The function call will
  392. block until one or more bytes of data has been written successfully, or
  393. until an error occurs.
  394. @param buffers The data to be written.
  395. @returns The number of bytes written.
  396. @throws boost::system::system_error Thrown on failure.
  397. @note The `write_some` operation may not transmit all of the data to the
  398. peer. Consider using the `net::write` function if you need to
  399. ensure that all data is written before the blocking operation completes.
  400. */
  401. template<class ConstBufferSequence>
  402. std::size_t
  403. write_some(ConstBufferSequence const& buffers)
  404. {
  405. return p_->write_some(buffers);
  406. }
  407. /** Write some data to the stream.
  408. This function is used to write data on the stream. The function call will
  409. block until one or more bytes of data has been written successfully, or
  410. until an error occurs.
  411. @param buffers The data to be written to the stream.
  412. @param ec Set to indicate what error occurred, if any.
  413. @returns The number of bytes written. Returns 0 if an error occurred.
  414. @note The `write_some` operation may not transmit all of the data to the
  415. peer. Consider using the `net::write` function if you need to
  416. ensure that all data is written before the blocking operation completes.
  417. */
  418. template<class ConstBufferSequence>
  419. std::size_t
  420. write_some(ConstBufferSequence const& buffers,
  421. boost::system::error_code& ec)
  422. {
  423. return p_->write_some(buffers, ec);
  424. }
  425. /** Start an asynchronous write.
  426. This function is used to asynchronously write one or more bytes of data to
  427. the stream. The function call always returns immediately.
  428. @param buffers The data to be written to the stream. Although the buffers
  429. object may be copied as necessary, ownership of the underlying buffers is
  430. retained by the caller, which must guarantee that they remain valid until
  431. the handler is called.
  432. @param handler The handler to be called when the write operation completes.
  433. Copies will be made of the handler as required. The equivalent function
  434. signature of the handler must be:
  435. @code void handler(
  436. const boost::system::error_code& error, // Result of operation.
  437. std::size_t bytes_transferred // Number of bytes written.
  438. ); @endcode
  439. @note The `async_write_some` operation may not transmit all of the data to
  440. the peer. Consider using the `net::async_write` function if you
  441. need to ensure that all data is written before the asynchronous operation
  442. completes.
  443. */
  444. template<class ConstBufferSequence,
  445. BOOST_BEAST_ASYNC_TPARAM2 WriteHandler = net::default_completion_token_t<executor_type>>
  446. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler, void(boost::system::error_code, std::size_t))
  447. async_write_some(ConstBufferSequence const& buffers,
  448. BOOST_ASIO_MOVE_ARG(WriteHandler) handler= net::default_completion_token_t<executor_type>{})
  449. {
  450. return p_->async_write_some(buffers,
  451. BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
  452. }
  453. /** Read some data from the stream.
  454. This function is used to read data from the stream. The function call will
  455. block until one or more bytes of data has been read successfully, or until
  456. an error occurs.
  457. @param buffers The buffers into which the data will be read.
  458. @returns The number of bytes read.
  459. @throws boost::system::system_error Thrown on failure.
  460. @note The `read_some` operation may not read all of the requested number of
  461. bytes. Consider using the `net::read` function if you need to ensure
  462. that the requested amount of data is read before the blocking operation
  463. completes.
  464. */
  465. template<class MutableBufferSequence>
  466. std::size_t
  467. read_some(MutableBufferSequence const& buffers)
  468. {
  469. return p_->read_some(buffers);
  470. }
  471. /** Read some data from the stream.
  472. This function is used to read data from the stream. The function call will
  473. block until one or more bytes of data has been read successfully, or until
  474. an error occurs.
  475. @param buffers The buffers into which the data will be read.
  476. @param ec Set to indicate what error occurred, if any.
  477. @returns The number of bytes read. Returns 0 if an error occurred.
  478. @note The `read_some` operation may not read all of the requested number of
  479. bytes. Consider using the `net::read` function if you need to ensure
  480. that the requested amount of data is read before the blocking operation
  481. completes.
  482. */
  483. template<class MutableBufferSequence>
  484. std::size_t
  485. read_some(MutableBufferSequence const& buffers,
  486. boost::system::error_code& ec)
  487. {
  488. return p_->read_some(buffers, ec);
  489. }
  490. /** Start an asynchronous read.
  491. This function is used to asynchronously read one or more bytes of data from
  492. the stream. The function call always returns immediately.
  493. @param buffers The buffers into which the data will be read. Although the
  494. buffers object may be copied as necessary, ownership of the underlying
  495. buffers is retained by the caller, which must guarantee that they remain
  496. valid until the handler is called.
  497. @param handler The handler to be called when the read operation completes.
  498. Copies will be made of the handler as required. The equivalent function
  499. signature of the handler must be:
  500. @code void handler(
  501. const boost::system::error_code& error, // Result of operation.
  502. std::size_t bytes_transferred // Number of bytes read.
  503. ); @endcode
  504. @note The `async_read_some` operation may not read all of the requested
  505. number of bytes. Consider using the `net::async_read` function
  506. if you need to ensure that the requested amount of data is read before
  507. the asynchronous operation completes.
  508. */
  509. template<class MutableBufferSequence,
  510. BOOST_BEAST_ASYNC_TPARAM2 ReadHandler = net::default_completion_token_t<executor_type>>
  511. BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ReadHandler, void(boost::system::error_code, std::size_t))
  512. async_read_some(MutableBufferSequence const& buffers,
  513. BOOST_ASIO_MOVE_ARG(ReadHandler) handler
  514. = net::default_completion_token_t<executor_type>{})
  515. {
  516. return p_->async_read_some(buffers,
  517. BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
  518. }
  519. // These hooks are used to inform boost::beast::websocket::stream on
  520. // how to tear down the connection as part of the WebSocket
  521. // protocol specifications
  522. #if ! BOOST_BEAST_DOXYGEN
  523. template<class SyncStream>
  524. friend
  525. void
  526. teardown(
  527. boost::beast::role_type role,
  528. ssl_stream<SyncStream>& stream,
  529. boost::system::error_code& ec);
  530. template<class AsyncStream, typename TeardownHandler>
  531. friend
  532. void
  533. async_teardown(
  534. boost::beast::role_type role,
  535. ssl_stream<AsyncStream>& stream,
  536. TeardownHandler&& handler);
  537. #endif
  538. };
  539. #if ! BOOST_BEAST_DOXYGEN
  540. template<class SyncStream>
  541. void
  542. teardown(
  543. boost::beast::role_type role,
  544. ssl_stream<SyncStream>& stream,
  545. boost::system::error_code& ec)
  546. {
  547. // Just forward it to the underlying ssl::stream
  548. using boost::beast::websocket::teardown;
  549. teardown(role, *stream.p_, ec);
  550. }
  551. template<class AsyncStream,
  552. typename TeardownHandler = net::default_completion_token_t<beast::executor_type<AsyncStream>>>
  553. void
  554. async_teardown(
  555. boost::beast::role_type role,
  556. ssl_stream<AsyncStream>& stream,
  557. TeardownHandler&& handler = net::default_completion_token_t<beast::executor_type<AsyncStream>>{})
  558. {
  559. // Just forward it to the underlying ssl::stream
  560. using boost::beast::websocket::async_teardown;
  561. async_teardown(role, *stream.p_,
  562. std::forward<TeardownHandler>(handler));
  563. }
  564. #endif
  565. } // beast
  566. } // boost
  567. #endif