ssl_stream.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. // VFALCO We include this because anyone who uses ssl will
  15. // very likely need to check for ssl::error::stream_truncated
  16. #include <boost/asio/ssl/error.hpp>
  17. #include <boost/asio/ssl/stream.hpp>
  18. namespace boost {
  19. namespace beast {
  20. /** (Deprecated: Use asio::ssl::stream instead.) Provides stream-oriented functionality using OpenSSL
  21. */
  22. template<class NextLayer>
  23. struct ssl_stream : net::ssl::stream<NextLayer>
  24. {
  25. using net::ssl::stream<NextLayer>::stream;
  26. };
  27. #if ! BOOST_BEAST_DOXYGEN
  28. template<class SyncStream>
  29. void
  30. teardown(
  31. boost::beast::role_type role,
  32. ssl_stream<SyncStream>& stream,
  33. boost::system::error_code& ec)
  34. {
  35. // Just forward it to the underlying ssl::stream
  36. using boost::beast::websocket::teardown;
  37. teardown(role, static_cast<net::ssl::stream<SyncStream>&>(stream), ec);
  38. }
  39. template<class AsyncStream,
  40. typename TeardownHandler = net::default_completion_token_t<beast::executor_type<AsyncStream>>>
  41. void
  42. async_teardown(
  43. boost::beast::role_type role,
  44. ssl_stream<AsyncStream>& stream,
  45. TeardownHandler&& handler = net::default_completion_token_t<beast::executor_type<AsyncStream>>{})
  46. {
  47. // Just forward it to the underlying ssl::stream
  48. using boost::beast::websocket::async_teardown;
  49. async_teardown(role, static_cast<net::ssl::stream<AsyncStream>&>(stream),
  50. std::forward<TeardownHandler>(handler));
  51. }
  52. #endif
  53. } // beast
  54. } // boost
  55. #endif