teardown.hpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 BHO_BEAST_WEBSOCKET_TEARDOWN_HPP
  10. #define BHO_BEAST_WEBSOCKET_TEARDOWN_HPP
  11. #include <asio2/bho/beast/core/detail/config.hpp>
  12. #include <asio2/bho/beast/core/error.hpp>
  13. #include <asio2/bho/beast/core/role.hpp>
  14. #include <asio/basic_stream_socket.hpp>
  15. #include <type_traits>
  16. namespace bho {
  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. @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. bho::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 <asio2/bho/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. `net::ip::tcp::socket` or any `net::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 The completion handler to invoke when the operation
  59. completes. The implementation takes ownership of the handler by
  60. performing a decay-copy. The equivalent function signature of
  61. the handler must be:
  62. @code
  63. void handler(
  64. error_code const& error // result of operation
  65. );
  66. @endcode
  67. If the handler has an associated immediate executor,
  68. an immediate completion will be dispatched to it.
  69. Otherwise, the handler will not be invoked from within
  70. this function. Invocation of the handler will be performed in a
  71. manner equivalent to using `net::post`.
  72. */
  73. template<
  74. class Socket,
  75. class TeardownHandler>
  76. void
  77. async_teardown(
  78. role_type role,
  79. Socket& socket,
  80. TeardownHandler&& handler)
  81. {
  82. bho::ignore_unused(role, socket, handler);
  83. /*
  84. If you are trying to use OpenSSL and this goes off, you need to
  85. add an include for <asio2/bho/beast/websocket/ssl.hpp>.
  86. If you are creating an instance of beast::websocket::stream with your
  87. own user defined type, you must provide an overload of teardown with
  88. the corresponding signature (including the role_type).
  89. */
  90. static_assert(sizeof(Socket)==-1,
  91. "Unknown Socket type in async_teardown.");
  92. }
  93. } // websocket
  94. //------------------------------------------------------------------------------
  95. namespace websocket {
  96. /** Tear down a `net::ip::tcp::socket`.
  97. This tears down a connection. The implementation will call
  98. the overload of this function based on the `Stream` parameter
  99. used to consruct the socket. When `Stream` is a user defined
  100. type, and not a `net::ip::tcp::socket` or any
  101. `net::ssl::stream`, callers are responsible for
  102. providing a suitable overload of this function.
  103. @param role The role of the local endpoint
  104. @param socket The socket to tear down.
  105. @param ec Set to the error if any occurred.
  106. */
  107. template<class Protocol, class Executor>
  108. void
  109. teardown(
  110. role_type role,
  111. net::basic_stream_socket<
  112. Protocol, Executor>& socket,
  113. error_code& ec);
  114. /** Start tearing down a `net::ip::tcp::socket`.
  115. This begins tearing down a connection asynchronously.
  116. The implementation will call the overload of this function
  117. based on the `Stream` parameter used to consruct the socket.
  118. When `Stream` is a user defined type, and not a
  119. `net::ip::tcp::socket` or any `net::ssl::stream`,
  120. callers are responsible for providing a suitable overload
  121. of this function.
  122. @param role The role of the local endpoint
  123. @param socket The socket to tear down.
  124. @param handler The completion handler to invoke when the operation
  125. completes. The implementation takes ownership of the handler by
  126. performing a decay-copy. The equivalent function signature of
  127. the handler must be:
  128. @code
  129. void handler(
  130. error_code const& error // result of operation
  131. );
  132. @endcode
  133. If the handler has an associated immediate executor,
  134. an immediate completion will be dispatched to it.
  135. Otherwise, the handler will not be invoked from within
  136. this function. Invocation of the handler will be performed in a
  137. manner equivalent to using `net::post`.
  138. @par Per-Operation Cancellation
  139. This asynchronous operation supports cancellation for the following
  140. net::cancellation_type values:
  141. @li @c net::cancellation_type::terminal
  142. @li @c net::cancellation_type::partial
  143. @li @c net::cancellation_type::total
  144. if they are also supported by the socket's @c async_wait operation.
  145. */
  146. template<
  147. class Protocol, class Executor,
  148. class TeardownHandler>
  149. void
  150. async_teardown(
  151. role_type role,
  152. net::basic_stream_socket<
  153. Protocol, Executor>& socket,
  154. TeardownHandler&& handler);
  155. } // websocket
  156. } // beast
  157. } // bho
  158. #include <asio2/bho/beast/websocket/impl/teardown.hpp>
  159. #endif