]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/asio/experimental/impl/redirect_error.hpp
Add patch for failing prerm scripts
[ceph.git] / ceph / src / boost / boost / asio / experimental / impl / redirect_error.hpp
1 //
2 // experimental/impl/redirect_error.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //
10
11 #ifndef BOOST_ASIO_EXPERIMENTAL_IMPL_REDIRECT_ERROR_HPP
12 #define BOOST_ASIO_EXPERIMENTAL_IMPL_REDIRECT_ERROR_HPP
13
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
18 #include <boost/asio/detail/config.hpp>
19 #include <boost/asio/associated_executor.hpp>
20 #include <boost/asio/associated_allocator.hpp>
21 #include <boost/asio/async_result.hpp>
22 #include <boost/asio/detail/handler_alloc_helpers.hpp>
23 #include <boost/asio/detail/handler_cont_helpers.hpp>
24 #include <boost/asio/detail/handler_invoke_helpers.hpp>
25 #include <boost/asio/detail/type_traits.hpp>
26 #include <boost/asio/detail/variadic_templates.hpp>
27 #include <boost/asio/handler_type.hpp>
28 #include <boost/system/system_error.hpp>
29
30 #include <boost/asio/detail/push_options.hpp>
31
32 namespace boost {
33 namespace asio {
34 namespace experimental {
35 namespace detail {
36
37 // Class to adapt a redirect_error_t as a completion handler.
38 template <typename Handler>
39 class redirect_error_handler
40 {
41 public:
42 template <typename CompletionToken>
43 redirect_error_handler(redirect_error_t<CompletionToken> e)
44 : ec_(e.ec_),
45 handler_(BOOST_ASIO_MOVE_CAST(CompletionToken)(e.token_))
46 {
47 }
48
49 void operator()()
50 {
51 handler_();
52 }
53
54 #if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
55
56 template <typename Arg, typename... Args>
57 typename enable_if<
58 !is_same<typename decay<Arg>::type, boost::system::error_code>::value
59 >::type
60 operator()(BOOST_ASIO_MOVE_ARG(Arg) arg, BOOST_ASIO_MOVE_ARG(Args)... args)
61 {
62 handler_(BOOST_ASIO_MOVE_CAST(Arg)(arg),
63 BOOST_ASIO_MOVE_CAST(Args)(args)...);
64 }
65
66 template <typename... Args>
67 void operator()(const boost::system::error_code& ec,
68 BOOST_ASIO_MOVE_ARG(Args)... args)
69 {
70 ec_ = ec;
71 handler_(BOOST_ASIO_MOVE_CAST(Args)(args)...);
72 }
73
74 #else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
75
76 template <typename Arg>
77 typename enable_if<
78 !is_same<typename decay<Arg>::type, boost::system::error_code>::value
79 >::type
80 operator()(BOOST_ASIO_MOVE_ARG(Arg) arg)
81 {
82 handler_(BOOST_ASIO_MOVE_CAST(Arg)(arg));
83 }
84
85 void operator()(const boost::system::error_code& ec)
86 {
87 ec_ = ec;
88 handler_();
89 }
90
91 #define BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF(n) \
92 template <typename Arg, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
93 typename enable_if< \
94 !is_same<typename decay<Arg>::type, boost::system::error_code>::value \
95 >::type \
96 operator()(BOOST_ASIO_MOVE_ARG(Arg) arg, BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) \
97 { \
98 handler_(BOOST_ASIO_MOVE_CAST(Arg)(arg), \
99 BOOST_ASIO_VARIADIC_MOVE_ARGS(n)); \
100 } \
101 \
102 template <BOOST_ASIO_VARIADIC_TPARAMS(n)> \
103 void operator()(const boost::system::error_code& ec, \
104 BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) \
105 { \
106 ec_ = ec; \
107 handler_(BOOST_ASIO_VARIADIC_MOVE_ARGS(n)); \
108 } \
109 /**/
110 BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF)
111 #undef BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF
112
113 #endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
114
115 //private:
116 boost::system::error_code& ec_;
117 Handler handler_;
118 };
119
120 template <typename Handler>
121 inline void* asio_handler_allocate(std::size_t size,
122 redirect_error_handler<Handler>* this_handler)
123 {
124 return boost_asio_handler_alloc_helpers::allocate(
125 size, this_handler->handler_);
126 }
127
128 template <typename Handler>
129 inline void asio_handler_deallocate(void* pointer, std::size_t size,
130 redirect_error_handler<Handler>* this_handler)
131 {
132 boost_asio_handler_alloc_helpers::deallocate(
133 pointer, size, this_handler->handler_);
134 }
135
136 template <typename Handler>
137 inline bool asio_handler_is_continuation(
138 redirect_error_handler<Handler>* this_handler)
139 {
140 return boost_asio_handler_cont_helpers::is_continuation(
141 this_handler->handler_);
142 }
143
144 template <typename Function, typename Handler>
145 inline void asio_handler_invoke(Function& function,
146 redirect_error_handler<Handler>* this_handler)
147 {
148 boost_asio_handler_invoke_helpers::invoke(
149 function, this_handler->handler_);
150 }
151
152 template <typename Function, typename Handler>
153 inline void asio_handler_invoke(const Function& function,
154 redirect_error_handler<Handler>* this_handler)
155 {
156 boost_asio_handler_invoke_helpers::invoke(
157 function, this_handler->handler_);
158 }
159
160 template <typename Signature>
161 struct redirect_error_signature
162 {
163 typedef Signature type;
164 };
165
166 #if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
167
168 template <typename R, typename... Args>
169 struct redirect_error_signature<R(boost::system::error_code, Args...)>
170 {
171 typedef R type(Args...);
172 };
173
174 template <typename R, typename... Args>
175 struct redirect_error_signature<R(const boost::system::error_code&, Args...)>
176 {
177 typedef R type(Args...);
178 };
179
180 #else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
181
182 template <typename R>
183 struct redirect_error_signature<R(boost::system::error_code)>
184 {
185 typedef R type();
186 };
187
188 template <typename R>
189 struct redirect_error_signature<R(const boost::system::error_code&)>
190 {
191 typedef R type();
192 };
193
194 #define BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF(n) \
195 template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
196 struct redirect_error_signature< \
197 R(boost::system::error_code, BOOST_ASIO_VARIADIC_TARGS(n))> \
198 { \
199 typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)); \
200 }; \
201 \
202 template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
203 struct redirect_error_signature< \
204 R(const boost::system::error_code&, BOOST_ASIO_VARIADIC_TARGS(n))> \
205 { \
206 typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)); \
207 }; \
208 /**/
209 BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF)
210 #undef BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF
211
212 #endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
213
214 } // namespace detail
215 } // namespace experimental
216
217 #if !defined(GENERATING_DOCUMENTATION)
218
219 template <typename CompletionToken, typename Signature>
220 struct async_result<experimental::redirect_error_t<CompletionToken>, Signature>
221 : async_result<CompletionToken,
222 typename experimental::detail::redirect_error_signature<Signature>::type>
223 {
224 typedef experimental::detail::redirect_error_handler<
225 typename async_result<CompletionToken,
226 typename experimental::detail::redirect_error_signature<Signature>::type>
227 ::completion_handler_type> completion_handler_type;
228
229 explicit async_result(completion_handler_type& h)
230 : async_result<CompletionToken,
231 typename experimental::detail::redirect_error_signature<
232 Signature>::type>(h.handler_)
233 {
234 }
235 };
236
237 #if !defined(BOOST_ASIO_NO_DEPRECATED)
238
239 template <typename CompletionToken, typename Signature>
240 struct handler_type<experimental::redirect_error_t<CompletionToken>, Signature>
241 {
242 typedef experimental::detail::redirect_error_handler<
243 typename async_result<CompletionToken,
244 typename experimental::detail::redirect_error_signature<Signature>::type>
245 ::completion_handler_type> type;
246 };
247
248 template <typename Handler>
249 struct async_result<experimental::detail::redirect_error_handler<Handler> >
250 : async_result<Handler>
251 {
252 explicit async_result(
253 experimental::detail::redirect_error_handler<Handler>& h)
254 : async_result<Handler>(h.handler_)
255 {
256 }
257 };
258
259 #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
260
261 template <typename Handler, typename Executor>
262 struct associated_executor<
263 experimental::detail::redirect_error_handler<Handler>, Executor>
264 {
265 typedef typename associated_executor<Handler, Executor>::type type;
266
267 static type get(
268 const experimental::detail::redirect_error_handler<Handler>& h,
269 const Executor& ex = Executor()) BOOST_ASIO_NOEXCEPT
270 {
271 return associated_executor<Handler, Executor>::get(h.handler_, ex);
272 }
273 };
274
275 template <typename Handler, typename Allocator>
276 struct associated_allocator<
277 experimental::detail::redirect_error_handler<Handler>, Allocator>
278 {
279 typedef typename associated_allocator<Handler, Allocator>::type type;
280
281 static type get(
282 const experimental::detail::redirect_error_handler<Handler>& h,
283 const Allocator& a = Allocator()) BOOST_ASIO_NOEXCEPT
284 {
285 return associated_allocator<Handler, Allocator>::get(h.handler_, a);
286 }
287 };
288
289 #endif // !defined(GENERATING_DOCUMENTATION)
290
291 } // namespace asio
292 } // namespace boost
293
294 #include <boost/asio/detail/pop_options.hpp>
295
296 #endif // BOOST_ASIO_EXPERIMENTAL_IMPL_REDIRECT_ERROR_HPP