websocket_7_teardown.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. #include <boost/beast/_experimental/unit_test/suite.hpp>
  10. #ifdef BOOST_MSVC
  11. #pragma warning(push)
  12. #pragma warning(disable: 4459) // declaration hides global declaration
  13. #endif
  14. #include <boost/beast.hpp>
  15. #include <boost/beast/ssl.hpp>
  16. #include <boost/asio.hpp>
  17. #include <boost/asio/ssl.hpp>
  18. namespace {
  19. #include "websocket_common.ipp"
  20. //[code_websocket_7_1
  21. struct custom_stream;
  22. void
  23. teardown(
  24. role_type role,
  25. custom_stream& stream,
  26. error_code& ec);
  27. template<class TeardownHandler>
  28. void
  29. async_teardown(
  30. role_type role,
  31. custom_stream& stream,
  32. TeardownHandler&& handler);
  33. //]
  34. void
  35. teardown(
  36. role_type,
  37. custom_stream&,
  38. error_code&)
  39. {
  40. }
  41. //[code_websocket_7_2
  42. template <class NextLayer>
  43. struct custom_wrapper
  44. {
  45. NextLayer next_layer;
  46. template<class... Args>
  47. explicit
  48. custom_wrapper(Args&&... args)
  49. : next_layer(std::forward<Args>(args)...)
  50. {
  51. }
  52. friend
  53. void
  54. teardown(
  55. role_type role,
  56. custom_wrapper& stream,
  57. error_code& ec)
  58. {
  59. using boost::beast::websocket::teardown;
  60. teardown(role, stream.next_layer, ec);
  61. }
  62. template<class TeardownHandler>
  63. friend
  64. void
  65. async_teardown(
  66. role_type role,
  67. custom_wrapper& stream,
  68. TeardownHandler&& handler)
  69. {
  70. using boost::beast::websocket::async_teardown;
  71. async_teardown(role, stream.next_layer, std::forward<TeardownHandler>(handler));
  72. }
  73. };
  74. //]
  75. void
  76. snippets()
  77. {
  78. //stream<tcp_stream> ws(ioc);
  79. {
  80. //[code_websocket_7_3
  81. //]
  82. }
  83. }
  84. struct websocket_7_test
  85. : public boost::beast::unit_test::suite
  86. {
  87. void
  88. run() override
  89. {
  90. BEAST_EXPECT(&snippets);
  91. BEAST_EXPECT(static_cast<void(*)(
  92. role_type, custom_stream&, error_code&)>(
  93. &teardown));
  94. }
  95. };
  96. BEAST_DEFINE_TESTSUITE(beast,doc,websocket_7);
  97. } // (anon)
  98. #ifdef BOOST_MSVC
  99. #pragma warning(pop)
  100. #endif