teardown.hpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //
  2. // Copyright (c) 2016-2017 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_WEBSOCKET_TEARDOWN_HPP
  10. #define BOOST_BEAST_WEBSOCKET_TEARDOWN_HPP
  11. #include <boost/beast/core/detail/config.hpp>
  12. #include <boost/beast/core/error.hpp>
  13. #include <boost/beast/websocket/role.hpp>
  14. #include <boost/asio/ip/tcp.hpp>
  15. #include <type_traits>
  16. namespace boost {
  17. namespace beast {
  18. namespace websocket {
  19. /** Tear down a connection.
  20. This tears down a connection. The implementation will call
  21. the overload of this function based on the `Socket` parameter
  22. used to consruct the socket. When `Socket` is a user defined
  23. type, and not a `boost::asio::ip::tcp::socket` or any
  24. `boost::asio::ssl::stream`, callers are responsible for
  25. providing a suitable overload of this function.
  26. @param role The role of the local endpoint
  27. @param socket The socket to tear down.
  28. @param ec Set to the error if any occurred.
  29. */
  30. template<class Socket>
  31. void
  32. teardown(
  33. role_type role,
  34. Socket& socket,
  35. error_code& ec)
  36. {
  37. boost::ignore_unused(role, socket, ec);
  38. /*
  39. If you are trying to use OpenSSL and this goes off, you need to
  40. add an include for <boost/beast/websocket/ssl.hpp>.
  41. If you are creating an instance of beast::websocket::stream with your
  42. own user defined type, you must provide an overload of teardown with
  43. the corresponding signature (including the role_type).
  44. */
  45. static_assert(sizeof(Socket)==-1,
  46. "Unknown Socket type in teardown.");
  47. }
  48. /** Start tearing down a connection.
  49. This begins tearing down a connection asynchronously.
  50. The implementation will call the overload of this function
  51. based on the `Socket` parameter used to consruct the socket.
  52. When `Stream` is a user defined type, and not a
  53. `boost::asio::ip::tcp::socket` or any `boost::asio::ssl::stream`,
  54. callers are responsible for providing a suitable overload
  55. of this function.
  56. @param role The role of the local endpoint
  57. @param socket The socket to tear down.
  58. @param handler Invoked when the operation completes.
  59. The handler may be moved or copied as needed.
  60. The equivalent function signature of the handler must be:
  61. @code void handler(
  62. error_code const& error // result of operation
  63. );
  64. @endcode
  65. Regardless of whether the asynchronous operation completes
  66. immediately or not, the handler will not be invoked from within
  67. this function. Invocation of the handler will be performed in a
  68. manner equivalent to using boost::asio::io_context::post().
  69. */
  70. template<
  71. class Socket,
  72. class TeardownHandler>
  73. void
  74. async_teardown(
  75. role_type role,
  76. Socket& socket,
  77. TeardownHandler&& handler)
  78. {
  79. boost::ignore_unused(role, socket, handler);
  80. /*
  81. If you are trying to use OpenSSL and this goes off, you need to
  82. add an include for <boost/beast/websocket/ssl.hpp>.
  83. If you are creating an instance of beast::websocket::stream with your
  84. own user defined type, you must provide an overload of teardown with
  85. the corresponding signature (including the role_type).
  86. */
  87. static_assert(sizeof(Socket)==-1,
  88. "Unknown Socket type in async_teardown.");
  89. }
  90. } // websocket
  91. //------------------------------------------------------------------------------
  92. namespace websocket {
  93. /** Tear down a `boost::asio::ip::tcp::socket`.
  94. This tears down a connection. The implementation will call
  95. the overload of this function based on the `Stream` parameter
  96. used to consruct the socket. When `Stream` is a user defined
  97. type, and not a `boost::asio::ip::tcp::socket` or any
  98. `boost::asio::ssl::stream`, callers are responsible for
  99. providing a suitable overload of this function.
  100. @param role The role of the local endpoint
  101. @param socket The socket to tear down.
  102. @param ec Set to the error if any occurred.
  103. */
  104. void
  105. teardown(
  106. role_type role,
  107. boost::asio::ip::tcp::socket& socket,
  108. error_code& ec);
  109. /** Start tearing down a `boost::asio::ip::tcp::socket`.
  110. This begins tearing down a connection asynchronously.
  111. The implementation will call the overload of this function
  112. based on the `Stream` parameter used to consruct the socket.
  113. When `Stream` is a user defined type, and not a
  114. `boost::asio::ip::tcp::socket` or any `boost::asio::ssl::stream`,
  115. callers are responsible for providing a suitable overload
  116. of this function.
  117. @param role The role of the local endpoint
  118. @param socket The socket to tear down.
  119. @param handler Invoked when the operation completes.
  120. The handler may be moved or copied as needed.
  121. The equivalent function signature of the handler must be:
  122. @code void handler(
  123. error_code const& error // result of operation
  124. );
  125. @endcode
  126. Regardless of whether the asynchronous operation completes
  127. immediately or not, the handler will not be invoked from within
  128. this function. Invocation of the handler will be performed in a
  129. manner equivalent to using boost::asio::io_context::post().
  130. */
  131. template<class TeardownHandler>
  132. void
  133. async_teardown(
  134. role_type role,
  135. boost::asio::ip::tcp::socket& socket,
  136. TeardownHandler&& handler);
  137. } // websocket
  138. } // beast
  139. } // boost
  140. #include <boost/beast/websocket/impl/teardown.ipp>
  141. #endif