teardown.hpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. @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. `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. Regardless of whether the asynchronous operation completes
  68. immediately or not, the handler will not be invoked from within
  69. this function. Invocation of the handler will be performed in a
  70. manner equivalent to using `net::post`.
  71. */
  72. template<
  73. class Socket,
  74. class TeardownHandler>
  75. void
  76. async_teardown(
  77. role_type role,
  78. Socket& socket,
  79. TeardownHandler&& handler)
  80. {
  81. boost::ignore_unused(role, socket, handler);
  82. /*
  83. If you are trying to use OpenSSL and this goes off, you need to
  84. add an include for <boost/beast/websocket/ssl.hpp>.
  85. If you are creating an instance of beast::websocket::stream with your
  86. own user defined type, you must provide an overload of teardown with
  87. the corresponding signature (including the role_type).
  88. */
  89. static_assert(sizeof(Socket)==-1,
  90. "Unknown Socket type in async_teardown.");
  91. }
  92. } // websocket
  93. //------------------------------------------------------------------------------
  94. namespace websocket {
  95. /** Tear down a `net::ip::tcp::socket`.
  96. This tears down a connection. The implementation will call
  97. the overload of this function based on the `Stream` parameter
  98. used to consruct the socket. When `Stream` is a user defined
  99. type, and not a `net::ip::tcp::socket` or any
  100. `net::ssl::stream`, callers are responsible for
  101. providing a suitable overload of this function.
  102. @param role The role of the local endpoint
  103. @param socket The socket to tear down.
  104. @param ec Set to the error if any occurred.
  105. */
  106. template<class Protocol, class Executor>
  107. void
  108. teardown(
  109. role_type role,
  110. net::basic_stream_socket<
  111. Protocol, Executor>& socket,
  112. error_code& ec);
  113. /** Start tearing down a `net::ip::tcp::socket`.
  114. This begins tearing down a connection asynchronously.
  115. The implementation will call the overload of this function
  116. based on the `Stream` parameter used to consruct the socket.
  117. When `Stream` is a user defined type, and not a
  118. `net::ip::tcp::socket` or any `net::ssl::stream`,
  119. callers are responsible for providing a suitable overload
  120. of this function.
  121. @param role The role of the local endpoint
  122. @param socket The socket to tear down.
  123. @param handler The completion handler to invoke when the operation
  124. completes. The implementation takes ownership of the handler by
  125. performing a decay-copy. The equivalent function signature of
  126. the handler must be:
  127. @code
  128. void handler(
  129. error_code const& error // result of operation
  130. );
  131. @endcode
  132. Regardless of whether the asynchronous operation completes
  133. immediately or not, the handler will not be invoked from within
  134. this function. Invocation of the handler will be performed in a
  135. manner equivalent to using `net::post`.
  136. */
  137. template<
  138. class Protocol, class Executor,
  139. class TeardownHandler>
  140. void
  141. async_teardown(
  142. role_type role,
  143. net::basic_stream_socket<
  144. Protocol, Executor>& socket,
  145. TeardownHandler&& handler);
  146. } // websocket
  147. } // beast
  148. } // boost
  149. #include <boost/beast/websocket/impl/teardown.hpp>
  150. #endif