teardown.hpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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_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/core/role.hpp>
  14. #include <boost/asio/basic_stream_socket.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 `net::ip::tcp::socket` or any
  24. `net::ssl::stream`, callers are responsible for
  25. providing a suitable overload of this function.
  26. @note
  27. This function serves as a customization point and is not intended
  28. to be called directly.
  29. @param role The role of the local endpoint
  30. @param socket The socket to tear down.
  31. @param ec Set to the error if any occurred.
  32. */
  33. template<class Socket>
  34. void
  35. teardown(
  36. role_type role,
  37. Socket& socket,
  38. error_code& ec)
  39. {
  40. boost::ignore_unused(role, socket, ec);
  41. /*
  42. If you are trying to use OpenSSL and this goes off, you need to
  43. add an include for <boost/beast/websocket/ssl.hpp>.
  44. If you are creating an instance of beast::websocket::stream with your
  45. own user defined type, you must provide an overload of teardown with
  46. the corresponding signature (including the role_type).
  47. */
  48. static_assert(sizeof(Socket)==-1,
  49. "Unknown Socket type in teardown.");
  50. }
  51. /** Start tearing down a connection.
  52. This begins tearing down a connection asynchronously.
  53. The implementation will call the overload of this function
  54. based on the `Socket` parameter used to consruct the socket.
  55. When `Stream` is a user defined type, and not a
  56. `net::ip::tcp::socket` or any `net::ssl::stream`,
  57. callers are responsible for providing a suitable overload
  58. of this function.
  59. @note
  60. This function serves as a customization point and is not intended
  61. to be called directly.
  62. @param role The role of the local endpoint
  63. @param socket The socket to tear down.
  64. @param handler The completion handler to invoke when the operation
  65. completes. The implementation takes ownership of the handler by
  66. performing a decay-copy. The equivalent function signature of
  67. the handler must be:
  68. @code
  69. void handler(
  70. error_code const& error // result of operation
  71. );
  72. @endcode
  73. If the handler has an associated immediate executor,
  74. an immediate completion will be dispatched to it.
  75. Otherwise, the handler will not be invoked from within
  76. this function. Invocation of the handler will be performed in a
  77. manner equivalent to using `net::post`.
  78. */
  79. template<
  80. class Socket,
  81. class TeardownHandler>
  82. void
  83. async_teardown(
  84. role_type role,
  85. Socket& socket,
  86. TeardownHandler&& handler)
  87. {
  88. boost::ignore_unused(role, socket, handler);
  89. /*
  90. If you are trying to use OpenSSL and this goes off, you need to
  91. add an include for <boost/beast/websocket/ssl.hpp>.
  92. If you are creating an instance of beast::websocket::stream with your
  93. own user defined type, you must provide an overload of teardown with
  94. the corresponding signature (including the role_type).
  95. */
  96. static_assert(sizeof(Socket)==-1,
  97. "Unknown Socket type in async_teardown.");
  98. }
  99. } // websocket
  100. //------------------------------------------------------------------------------
  101. namespace websocket {
  102. /** Tear down a `net::ip::tcp::socket`.
  103. This tears down a connection. The implementation will call
  104. the overload of this function based on the `Stream` parameter
  105. used to consruct the socket. When `Stream` is a user defined
  106. type, and not a `net::ip::tcp::socket` or any
  107. `net::ssl::stream`, callers are responsible for
  108. providing a suitable overload of this function.
  109. @note
  110. This function serves as a customization point and is not intended
  111. to be called directly.
  112. @param role The role of the local endpoint
  113. @param socket The socket to tear down.
  114. @param ec Set to the error if any occurred.
  115. */
  116. template<class Protocol, class Executor>
  117. void
  118. teardown(
  119. role_type role,
  120. net::basic_stream_socket<
  121. Protocol, Executor>& socket,
  122. error_code& ec);
  123. /** Start tearing down a `net::ip::tcp::socket`.
  124. This begins tearing down a connection asynchronously.
  125. The implementation will call the overload of this function
  126. based on the `Stream` parameter used to consruct the socket.
  127. When `Stream` is a user defined type, and not a
  128. `net::ip::tcp::socket` or any `net::ssl::stream`,
  129. callers are responsible for providing a suitable overload
  130. of this function.
  131. @note
  132. This function serves as a customization point and is not intended
  133. to be called directly.
  134. @param role The role of the local endpoint
  135. @param socket The socket to tear down.
  136. @param handler The completion handler to invoke when the operation
  137. completes. The implementation takes ownership of the handler by
  138. performing a decay-copy. The equivalent function signature of
  139. the handler must be:
  140. @code
  141. void handler(
  142. error_code const& error // result of operation
  143. );
  144. @endcode
  145. If the handler has an associated immediate executor,
  146. an immediate completion will be dispatched to it.
  147. Otherwise, the handler will not be invoked from within
  148. this function. Invocation of the handler will be performed in a
  149. manner equivalent to using `net::post`.
  150. @par Per-Operation Cancellation
  151. This asynchronous operation supports cancellation for the following
  152. net::cancellation_type values:
  153. @li @c net::cancellation_type::terminal
  154. @li @c net::cancellation_type::partial
  155. @li @c net::cancellation_type::total
  156. if they are also supported by the socket's @c async_wait operation.
  157. */
  158. template<
  159. class Protocol, class Executor,
  160. class TeardownHandler>
  161. void
  162. async_teardown(
  163. role_type role,
  164. net::basic_stream_socket<
  165. Protocol, Executor>& socket,
  166. TeardownHandler&& handler);
  167. } // websocket
  168. } // beast
  169. } // boost
  170. #include <boost/beast/websocket/impl/teardown.hpp>
  171. #endif