]> git.proxmox.com Git - ceph.git/blame - ceph/src/Beast/include/beast/websocket/teardown.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / Beast / include / beast / websocket / teardown.hpp
CommitLineData
7c673cae
FG
1//
2// Copyright (c) 2013-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
8#ifndef BEAST_WEBSOCKET_TEARDOWN_HPP
9#define BEAST_WEBSOCKET_TEARDOWN_HPP
10
11#include <beast/config.hpp>
12#include <beast/websocket/error.hpp>
13#include <boost/asio/ip/tcp.hpp>
14#include <type_traits>
15
16namespace beast {
17namespace websocket {
18
19/** Tag type used to find @ref beast::websocket::teardown and @ref beast::websocket::async_teardown overloads
20
21 Overloads of @ref beast::websocket::teardown and
22 @ref beast::websocket::async_teardown for user defined types
23 must take a value of type @ref teardown_tag in the first
24 argument in order to be found by the implementation.
25*/
26struct teardown_tag {};
27
28/** Tear down a connection.
29
30 This tears down a connection. The implementation will call
31 the overload of this function based on the `Socket` parameter
32 used to consruct the socket. When `Socket` is a user defined
33 type, and not a `boost::asio::ip::tcp::socket` or any
34 `boost::asio::ssl::stream`, callers are responsible for
35 providing a suitable overload of this function.
36
37 @param socket The socket to tear down.
38
39 @param ec Set to the error if any occurred.
40*/
41template<class Socket>
42void
43teardown(teardown_tag, Socket& socket, error_code& ec)
44{
45/*
46 If you are trying to use OpenSSL and this goes off, you need to
47 add an include for <beast/websocket/ssl.hpp>.
48
49 If you are creating an instance of beast::websocket::stream with your
50 own user defined type, you must provide an overload of teardown with
51 the corresponding signature (including the teardown_tag).
52*/
53 static_assert(sizeof(Socket)==-1,
54 "Unknown Socket type in teardown.");
55}
56
57/** Start tearing down a connection.
58
59 This begins tearing down a connection asynchronously.
60 The implementation will call the overload of this function
61 based on the `Socket` parameter used to consruct the socket.
62 When `Stream` is a user defined type, and not a
63 `boost::asio::ip::tcp::socket` or any `boost::asio::ssl::stream`,
64 callers are responsible for providing a suitable overload
65 of this function.
66
67 @param socket The socket to tear down.
68
69 @param handler The handler to be called when the request completes.
70 Copies will be made of the handler as required. The equivalent
71 function signature of the handler must be:
72 @code void handler(
73 error_code const& error // result of operation
74 );
75 @endcode
76 Regardless of whether the asynchronous operation completes
77 immediately or not, the handler will not be invoked from within
78 this function. Invocation of the handler will be performed in a
79 manner equivalent to using boost::asio::io_service::post().
80
81*/
82template<class Socket, class TeardownHandler>
83void
84async_teardown(teardown_tag, Socket& socket, TeardownHandler&& handler)
85{
86/*
87 If you are trying to use OpenSSL and this goes off, you need to
88 add an include for <beast/websocket/ssl.hpp>.
89
90 If you are creating an instance of beast::websocket::stream with your
91 own user defined type, you must provide an overload of teardown with
92 the corresponding signature (including the teardown_tag).
93*/
94 static_assert(sizeof(Socket)==-1,
95 "Unknown Socket type in async_teardown.");
96}
97
98} // websocket
99
100//------------------------------------------------------------------------------
101
102namespace websocket_helpers {
103
104// Calls to teardown and async_teardown must be made from
105// a namespace that does not contain any overloads of these
106// functions. The websocket_helpers namespace is defined here
107// for that purpose.
108
109template<class Socket>
110inline
111void
112call_teardown(Socket& socket, error_code& ec)
113{
114 using websocket::teardown;
115 teardown(websocket::teardown_tag{}, socket, ec);
116}
117
118template<class Socket, class TeardownHandler>
119inline
120void
121call_async_teardown(Socket& socket, TeardownHandler&& handler)
122{
123 using websocket::async_teardown;
124 async_teardown(websocket::teardown_tag{}, socket,
125 std::forward<TeardownHandler>(handler));
126}
127
128} // websocket_helpers
129
130//------------------------------------------------------------------------------
131
132namespace websocket {
133
134/** Tear down a `boost::asio::ip::tcp::socket`.
135
136 This tears down a connection. The implementation will call
137 the overload of this function based on the `Stream` parameter
138 used to consruct the socket. When `Stream` is a user defined
139 type, and not a `boost::asio::ip::tcp::socket` or any
140 `boost::asio::ssl::stream`, callers are responsible for
141 providing a suitable overload of this function.
142
143 @param socket The socket to tear down.
144
145 @param ec Set to the error if any occurred.
146*/
147void
148teardown(teardown_tag,
149 boost::asio::ip::tcp::socket& socket, error_code& ec);
150
151/** Start tearing down a `boost::asio::ip::tcp::socket`.
152
153 This begins tearing down a connection asynchronously.
154 The implementation will call the overload of this function
155 based on the `Stream` parameter used to consruct the socket.
156 When `Stream` is a user defined type, and not a
157 `boost::asio::ip::tcp::socket` or any `boost::asio::ssl::stream`,
158 callers are responsible for providing a suitable overload
159 of this function.
160
161 @param socket The socket to tear down.
162
163 @param handler The handler to be called when the request completes.
164 Copies will be made of the handler as required. The equivalent
165 function signature of the handler must be:
166 @code void handler(
167 error_code const& error // result of operation
168 );
169 @endcode
170 Regardless of whether the asynchronous operation completes
171 immediately or not, the handler will not be invoked from within
172 this function. Invocation of the handler will be performed in a
173 manner equivalent to using boost::asio::io_service::post().
174
175*/
176template<class TeardownHandler>
177void
178async_teardown(teardown_tag,
179 boost::asio::ip::tcp::socket& socket, TeardownHandler&& handler);
180
181} // websocket
182} // beast
183
184#include <beast/websocket/impl/teardown.ipp>
185
186#endif