]>
Commit | Line | Data |
---|---|---|
92f5a8d4 TL |
1 | |
2 | // impl/redirect_error.hpp | |
3 | // ~~~~~~~~~~~~~~~~~~~~~~~ | |
11fdf7f2 | 4 | // |
1e59de90 | 5 | // Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com) |
11fdf7f2 TL |
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 | ||
92f5a8d4 TL |
11 | #ifndef BOOST_ASIO_IMPL_REDIRECT_ERROR_HPP |
12 | #define BOOST_ASIO_IMPL_REDIRECT_ERROR_HPP | |
11fdf7f2 TL |
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> | |
1e59de90 | 19 | #include <boost/asio/associator.hpp> |
11fdf7f2 TL |
20 | #include <boost/asio/async_result.hpp> |
21 | #include <boost/asio/detail/handler_alloc_helpers.hpp> | |
22 | #include <boost/asio/detail/handler_cont_helpers.hpp> | |
23 | #include <boost/asio/detail/handler_invoke_helpers.hpp> | |
24 | #include <boost/asio/detail/type_traits.hpp> | |
25 | #include <boost/asio/detail/variadic_templates.hpp> | |
11fdf7f2 TL |
26 | #include <boost/system/system_error.hpp> |
27 | ||
28 | #include <boost/asio/detail/push_options.hpp> | |
29 | ||
30 | namespace boost { | |
31 | namespace asio { | |
11fdf7f2 TL |
32 | namespace detail { |
33 | ||
34 | // Class to adapt a redirect_error_t as a completion handler. | |
35 | template <typename Handler> | |
36 | class redirect_error_handler | |
37 | { | |
38 | public: | |
92f5a8d4 TL |
39 | typedef void result_type; |
40 | ||
11fdf7f2 TL |
41 | template <typename CompletionToken> |
42 | redirect_error_handler(redirect_error_t<CompletionToken> e) | |
43 | : ec_(e.ec_), | |
44 | handler_(BOOST_ASIO_MOVE_CAST(CompletionToken)(e.token_)) | |
45 | { | |
46 | } | |
47 | ||
92f5a8d4 TL |
48 | template <typename RedirectedHandler> |
49 | redirect_error_handler(boost::system::error_code& ec, | |
50 | BOOST_ASIO_MOVE_ARG(RedirectedHandler) h) | |
51 | : ec_(ec), | |
52 | handler_(BOOST_ASIO_MOVE_CAST(RedirectedHandler)(h)) | |
53 | { | |
54 | } | |
55 | ||
11fdf7f2 TL |
56 | void operator()() |
57 | { | |
1e59de90 | 58 | BOOST_ASIO_MOVE_OR_LVALUE(Handler)(handler_)(); |
11fdf7f2 TL |
59 | } |
60 | ||
61 | #if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) | |
62 | ||
63 | template <typename Arg, typename... Args> | |
64 | typename enable_if< | |
65 | !is_same<typename decay<Arg>::type, boost::system::error_code>::value | |
66 | >::type | |
67 | operator()(BOOST_ASIO_MOVE_ARG(Arg) arg, BOOST_ASIO_MOVE_ARG(Args)... args) | |
68 | { | |
1e59de90 TL |
69 | BOOST_ASIO_MOVE_OR_LVALUE(Handler)(handler_)( |
70 | BOOST_ASIO_MOVE_CAST(Arg)(arg), | |
11fdf7f2 TL |
71 | BOOST_ASIO_MOVE_CAST(Args)(args)...); |
72 | } | |
73 | ||
74 | template <typename... Args> | |
75 | void operator()(const boost::system::error_code& ec, | |
76 | BOOST_ASIO_MOVE_ARG(Args)... args) | |
77 | { | |
78 | ec_ = ec; | |
1e59de90 TL |
79 | BOOST_ASIO_MOVE_OR_LVALUE(Handler)(handler_)( |
80 | BOOST_ASIO_MOVE_CAST(Args)(args)...); | |
11fdf7f2 TL |
81 | } |
82 | ||
83 | #else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) | |
84 | ||
85 | template <typename Arg> | |
86 | typename enable_if< | |
87 | !is_same<typename decay<Arg>::type, boost::system::error_code>::value | |
88 | >::type | |
89 | operator()(BOOST_ASIO_MOVE_ARG(Arg) arg) | |
90 | { | |
1e59de90 TL |
91 | BOOST_ASIO_MOVE_OR_LVALUE(Handler)(handler_)( |
92 | BOOST_ASIO_MOVE_CAST(Arg)(arg)); | |
11fdf7f2 TL |
93 | } |
94 | ||
95 | void operator()(const boost::system::error_code& ec) | |
96 | { | |
97 | ec_ = ec; | |
1e59de90 | 98 | BOOST_ASIO_MOVE_OR_LVALUE(Handler)(handler_)(); |
11fdf7f2 TL |
99 | } |
100 | ||
101 | #define BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF(n) \ | |
102 | template <typename Arg, BOOST_ASIO_VARIADIC_TPARAMS(n)> \ | |
103 | typename enable_if< \ | |
104 | !is_same<typename decay<Arg>::type, boost::system::error_code>::value \ | |
105 | >::type \ | |
106 | operator()(BOOST_ASIO_MOVE_ARG(Arg) arg, BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) \ | |
107 | { \ | |
1e59de90 TL |
108 | BOOST_ASIO_MOVE_OR_LVALUE(Handler)(handler_)( \ |
109 | BOOST_ASIO_MOVE_CAST(Arg)(arg), \ | |
11fdf7f2 TL |
110 | BOOST_ASIO_VARIADIC_MOVE_ARGS(n)); \ |
111 | } \ | |
112 | \ | |
113 | template <BOOST_ASIO_VARIADIC_TPARAMS(n)> \ | |
114 | void operator()(const boost::system::error_code& ec, \ | |
115 | BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) \ | |
116 | { \ | |
117 | ec_ = ec; \ | |
1e59de90 TL |
118 | BOOST_ASIO_MOVE_OR_LVALUE(Handler)(handler_)( \ |
119 | BOOST_ASIO_VARIADIC_MOVE_ARGS(n)); \ | |
11fdf7f2 TL |
120 | } \ |
121 | /**/ | |
122 | BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF) | |
123 | #undef BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF | |
124 | ||
125 | #endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) | |
126 | ||
127 | //private: | |
128 | boost::system::error_code& ec_; | |
129 | Handler handler_; | |
130 | }; | |
131 | ||
132 | template <typename Handler> | |
20effc67 TL |
133 | inline asio_handler_allocate_is_deprecated |
134 | asio_handler_allocate(std::size_t size, | |
11fdf7f2 TL |
135 | redirect_error_handler<Handler>* this_handler) |
136 | { | |
20effc67 TL |
137 | #if defined(BOOST_ASIO_NO_DEPRECATED) |
138 | boost_asio_handler_alloc_helpers::allocate(size, this_handler->handler_); | |
139 | return asio_handler_allocate_is_no_longer_used(); | |
140 | #else // defined(BOOST_ASIO_NO_DEPRECATED) | |
11fdf7f2 TL |
141 | return boost_asio_handler_alloc_helpers::allocate( |
142 | size, this_handler->handler_); | |
20effc67 | 143 | #endif // defined(BOOST_ASIO_NO_DEPRECATED) |
11fdf7f2 TL |
144 | } |
145 | ||
146 | template <typename Handler> | |
20effc67 TL |
147 | inline asio_handler_deallocate_is_deprecated |
148 | asio_handler_deallocate(void* pointer, std::size_t size, | |
11fdf7f2 TL |
149 | redirect_error_handler<Handler>* this_handler) |
150 | { | |
151 | boost_asio_handler_alloc_helpers::deallocate( | |
152 | pointer, size, this_handler->handler_); | |
20effc67 TL |
153 | #if defined(BOOST_ASIO_NO_DEPRECATED) |
154 | return asio_handler_deallocate_is_no_longer_used(); | |
155 | #endif // defined(BOOST_ASIO_NO_DEPRECATED) | |
11fdf7f2 TL |
156 | } |
157 | ||
158 | template <typename Handler> | |
159 | inline bool asio_handler_is_continuation( | |
160 | redirect_error_handler<Handler>* this_handler) | |
161 | { | |
162 | return boost_asio_handler_cont_helpers::is_continuation( | |
163 | this_handler->handler_); | |
164 | } | |
165 | ||
166 | template <typename Function, typename Handler> | |
20effc67 TL |
167 | inline asio_handler_invoke_is_deprecated |
168 | asio_handler_invoke(Function& function, | |
11fdf7f2 TL |
169 | redirect_error_handler<Handler>* this_handler) |
170 | { | |
171 | boost_asio_handler_invoke_helpers::invoke( | |
172 | function, this_handler->handler_); | |
20effc67 TL |
173 | #if defined(BOOST_ASIO_NO_DEPRECATED) |
174 | return asio_handler_invoke_is_no_longer_used(); | |
175 | #endif // defined(BOOST_ASIO_NO_DEPRECATED) | |
11fdf7f2 TL |
176 | } |
177 | ||
178 | template <typename Function, typename Handler> | |
20effc67 TL |
179 | inline asio_handler_invoke_is_deprecated |
180 | asio_handler_invoke(const Function& function, | |
11fdf7f2 TL |
181 | redirect_error_handler<Handler>* this_handler) |
182 | { | |
183 | boost_asio_handler_invoke_helpers::invoke( | |
184 | function, this_handler->handler_); | |
20effc67 TL |
185 | #if defined(BOOST_ASIO_NO_DEPRECATED) |
186 | return asio_handler_invoke_is_no_longer_used(); | |
187 | #endif // defined(BOOST_ASIO_NO_DEPRECATED) | |
11fdf7f2 TL |
188 | } |
189 | ||
190 | template <typename Signature> | |
191 | struct redirect_error_signature | |
192 | { | |
193 | typedef Signature type; | |
194 | }; | |
195 | ||
196 | #if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) | |
197 | ||
198 | template <typename R, typename... Args> | |
199 | struct redirect_error_signature<R(boost::system::error_code, Args...)> | |
200 | { | |
201 | typedef R type(Args...); | |
202 | }; | |
203 | ||
204 | template <typename R, typename... Args> | |
205 | struct redirect_error_signature<R(const boost::system::error_code&, Args...)> | |
206 | { | |
207 | typedef R type(Args...); | |
208 | }; | |
209 | ||
1e59de90 TL |
210 | # if defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS) |
211 | ||
212 | template <typename R, typename... Args> | |
213 | struct redirect_error_signature<R(boost::system::error_code, Args...) &> | |
214 | { | |
215 | typedef R type(Args...) &; | |
216 | }; | |
217 | ||
218 | template <typename R, typename... Args> | |
219 | struct redirect_error_signature<R(const boost::system::error_code&, Args...) &> | |
220 | { | |
221 | typedef R type(Args...) &; | |
222 | }; | |
223 | ||
224 | template <typename R, typename... Args> | |
225 | struct redirect_error_signature<R(boost::system::error_code, Args...) &&> | |
226 | { | |
227 | typedef R type(Args...) &&; | |
228 | }; | |
229 | ||
230 | template <typename R, typename... Args> | |
231 | struct redirect_error_signature<R(const boost::system::error_code&, Args...) &&> | |
232 | { | |
233 | typedef R type(Args...) &&; | |
234 | }; | |
235 | ||
236 | # if defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE) | |
237 | ||
238 | template <typename R, typename... Args> | |
239 | struct redirect_error_signature< | |
240 | R(boost::system::error_code, Args...) noexcept> | |
241 | { | |
242 | typedef R type(Args...) & noexcept; | |
243 | }; | |
244 | ||
245 | template <typename R, typename... Args> | |
246 | struct redirect_error_signature< | |
247 | R(const boost::system::error_code&, Args...) noexcept> | |
248 | { | |
249 | typedef R type(Args...) & noexcept; | |
250 | }; | |
251 | ||
252 | template <typename R, typename... Args> | |
253 | struct redirect_error_signature< | |
254 | R(boost::system::error_code, Args...) & noexcept> | |
255 | { | |
256 | typedef R type(Args...) & noexcept; | |
257 | }; | |
258 | ||
259 | template <typename R, typename... Args> | |
260 | struct redirect_error_signature< | |
261 | R(const boost::system::error_code&, Args...) & noexcept> | |
262 | { | |
263 | typedef R type(Args...) & noexcept; | |
264 | }; | |
265 | ||
266 | template <typename R, typename... Args> | |
267 | struct redirect_error_signature< | |
268 | R(boost::system::error_code, Args...) && noexcept> | |
269 | { | |
270 | typedef R type(Args...) && noexcept; | |
271 | }; | |
272 | ||
273 | template <typename R, typename... Args> | |
274 | struct redirect_error_signature< | |
275 | R(const boost::system::error_code&, Args...) && noexcept> | |
276 | { | |
277 | typedef R type(Args...) && noexcept; | |
278 | }; | |
279 | ||
280 | # endif // defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE) | |
281 | # endif // defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS) | |
11fdf7f2 TL |
282 | #else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) |
283 | ||
284 | template <typename R> | |
285 | struct redirect_error_signature<R(boost::system::error_code)> | |
286 | { | |
287 | typedef R type(); | |
288 | }; | |
289 | ||
290 | template <typename R> | |
291 | struct redirect_error_signature<R(const boost::system::error_code&)> | |
292 | { | |
293 | typedef R type(); | |
294 | }; | |
295 | ||
296 | #define BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF(n) \ | |
297 | template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \ | |
298 | struct redirect_error_signature< \ | |
299 | R(boost::system::error_code, BOOST_ASIO_VARIADIC_TARGS(n))> \ | |
300 | { \ | |
301 | typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)); \ | |
302 | }; \ | |
303 | \ | |
304 | template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \ | |
305 | struct redirect_error_signature< \ | |
306 | R(const boost::system::error_code&, BOOST_ASIO_VARIADIC_TARGS(n))> \ | |
307 | { \ | |
308 | typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)); \ | |
309 | }; \ | |
310 | /**/ | |
311 | BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF) | |
312 | #undef BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF | |
313 | ||
1e59de90 TL |
314 | # if defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS) |
315 | ||
316 | template <typename R> | |
317 | struct redirect_error_signature<R(boost::system::error_code) &> | |
318 | { | |
319 | typedef R type() &; | |
320 | }; | |
321 | ||
322 | template <typename R> | |
323 | struct redirect_error_signature<R(const boost::system::error_code&) &> | |
324 | { | |
325 | typedef R type() &; | |
326 | }; | |
327 | ||
328 | template <typename R> | |
329 | struct redirect_error_signature<R(boost::system::error_code) &&> | |
330 | { | |
331 | typedef R type() &&; | |
332 | }; | |
333 | ||
334 | template <typename R> | |
335 | struct redirect_error_signature<R(const boost::system::error_code&) &&> | |
336 | { | |
337 | typedef R type() &&; | |
338 | }; | |
339 | ||
340 | #define BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF(n) \ | |
341 | template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \ | |
342 | struct redirect_error_signature< \ | |
343 | R(boost::system::error_code, BOOST_ASIO_VARIADIC_TARGS(n)) &> \ | |
344 | { \ | |
345 | typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)) &; \ | |
346 | }; \ | |
347 | \ | |
348 | template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \ | |
349 | struct redirect_error_signature< \ | |
350 | R(const boost::system::error_code&, BOOST_ASIO_VARIADIC_TARGS(n)) &> \ | |
351 | { \ | |
352 | typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)) &; \ | |
353 | }; \ | |
354 | \ | |
355 | template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \ | |
356 | struct redirect_error_signature< \ | |
357 | R(boost::system::error_code, BOOST_ASIO_VARIADIC_TARGS(n)) &&> \ | |
358 | { \ | |
359 | typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)) &&; \ | |
360 | }; \ | |
361 | \ | |
362 | template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \ | |
363 | struct redirect_error_signature< \ | |
364 | R(const boost::system::error_code&, BOOST_ASIO_VARIADIC_TARGS(n)) &&> \ | |
365 | { \ | |
366 | typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)) &&; \ | |
367 | }; \ | |
368 | /**/ | |
369 | BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF) | |
370 | #undef BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF | |
371 | ||
372 | # if defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE) | |
373 | ||
374 | template <typename R> | |
375 | struct redirect_error_signature< | |
376 | R(boost::system::error_code) noexcept> | |
377 | { | |
378 | typedef R type() noexcept; | |
379 | }; | |
380 | ||
381 | template <typename R> | |
382 | struct redirect_error_signature< | |
383 | R(const boost::system::error_code&) noexcept> | |
384 | { | |
385 | typedef R type() noexcept; | |
386 | }; | |
387 | ||
388 | template <typename R> | |
389 | struct redirect_error_signature< | |
390 | R(boost::system::error_code) & noexcept> | |
391 | { | |
392 | typedef R type() & noexcept; | |
393 | }; | |
394 | ||
395 | template <typename R> | |
396 | struct redirect_error_signature< | |
397 | R(const boost::system::error_code&) & noexcept> | |
398 | { | |
399 | typedef R type() & noexcept; | |
400 | }; | |
401 | ||
402 | template <typename R> | |
403 | struct redirect_error_signature< | |
404 | R(boost::system::error_code) && noexcept> | |
405 | { | |
406 | typedef R type() && noexcept; | |
407 | }; | |
408 | ||
409 | template <typename R> | |
410 | struct redirect_error_signature< | |
411 | R(const boost::system::error_code&) && noexcept> | |
412 | { | |
413 | typedef R type() && noexcept; | |
414 | }; | |
415 | ||
416 | #define BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF(n) \ | |
417 | template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \ | |
418 | struct redirect_error_signature< \ | |
419 | R(boost::system::error_code, BOOST_ASIO_VARIADIC_TARGS(n)) noexcept> \ | |
420 | { \ | |
421 | typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)) noexcept; \ | |
422 | }; \ | |
423 | \ | |
424 | template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \ | |
425 | struct redirect_error_signature< \ | |
426 | R(const boost::system::error_code&, \ | |
427 | BOOST_ASIO_VARIADIC_TARGS(n)) noexcept> \ | |
428 | { \ | |
429 | typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)) noexcept; \ | |
430 | }; \ | |
431 | \ | |
432 | template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \ | |
433 | struct redirect_error_signature< \ | |
434 | R(boost::system::error_code, \ | |
435 | BOOST_ASIO_VARIADIC_TARGS(n)) & noexcept> \ | |
436 | { \ | |
437 | typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)) & noexcept; \ | |
438 | }; \ | |
439 | \ | |
440 | template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \ | |
441 | struct redirect_error_signature< \ | |
442 | R(const boost::system::error_code&, \ | |
443 | BOOST_ASIO_VARIADIC_TARGS(n)) & noexcept> \ | |
444 | { \ | |
445 | typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)) & noexcept; \ | |
446 | }; \ | |
447 | \ | |
448 | template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \ | |
449 | struct redirect_error_signature< \ | |
450 | R(boost::system::error_code, \ | |
451 | BOOST_ASIO_VARIADIC_TARGS(n)) && noexcept> \ | |
452 | { \ | |
453 | typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)) && noexcept; \ | |
454 | }; \ | |
455 | \ | |
456 | template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \ | |
457 | struct redirect_error_signature< \ | |
458 | R(const boost::system::error_code&, \ | |
459 | BOOST_ASIO_VARIADIC_TARGS(n)) && noexcept> \ | |
460 | { \ | |
461 | typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)) && noexcept; \ | |
462 | }; \ | |
463 | /**/ | |
464 | BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF) | |
465 | #undef BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF | |
466 | ||
467 | # endif // defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE) | |
468 | # endif // defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS) | |
11fdf7f2 TL |
469 | #endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) |
470 | ||
471 | } // namespace detail | |
11fdf7f2 TL |
472 | |
473 | #if !defined(GENERATING_DOCUMENTATION) | |
474 | ||
475 | template <typename CompletionToken, typename Signature> | |
92f5a8d4 | 476 | struct async_result<redirect_error_t<CompletionToken>, Signature> |
11fdf7f2 | 477 | { |
92f5a8d4 TL |
478 | typedef typename async_result<CompletionToken, |
479 | typename detail::redirect_error_signature<Signature>::type> | |
480 | ::return_type return_type; | |
481 | ||
482 | template <typename Initiation> | |
483 | struct init_wrapper | |
11fdf7f2 | 484 | { |
92f5a8d4 TL |
485 | template <typename Init> |
486 | init_wrapper(boost::system::error_code& ec, BOOST_ASIO_MOVE_ARG(Init) init) | |
487 | : ec_(ec), | |
488 | initiation_(BOOST_ASIO_MOVE_CAST(Init)(init)) | |
489 | { | |
490 | } | |
11fdf7f2 | 491 | |
92f5a8d4 | 492 | #if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) |
11fdf7f2 | 493 | |
92f5a8d4 TL |
494 | template <typename Handler, typename... Args> |
495 | void operator()( | |
496 | BOOST_ASIO_MOVE_ARG(Handler) handler, | |
497 | BOOST_ASIO_MOVE_ARG(Args)... args) | |
498 | { | |
499 | BOOST_ASIO_MOVE_CAST(Initiation)(initiation_)( | |
500 | detail::redirect_error_handler< | |
501 | typename decay<Handler>::type>( | |
502 | ec_, BOOST_ASIO_MOVE_CAST(Handler)(handler)), | |
503 | BOOST_ASIO_MOVE_CAST(Args)(args)...); | |
504 | } | |
11fdf7f2 | 505 | |
92f5a8d4 TL |
506 | #else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) |
507 | ||
508 | template <typename Handler> | |
509 | void operator()( | |
510 | BOOST_ASIO_MOVE_ARG(Handler) handler) | |
511 | { | |
512 | BOOST_ASIO_MOVE_CAST(Initiation)(initiation_)( | |
513 | detail::redirect_error_handler< | |
514 | typename decay<Handler>::type>( | |
515 | ec_, BOOST_ASIO_MOVE_CAST(Handler)(handler))); | |
516 | } | |
517 | ||
518 | #define BOOST_ASIO_PRIVATE_INIT_WRAPPER_DEF(n) \ | |
519 | template <typename Handler, BOOST_ASIO_VARIADIC_TPARAMS(n)> \ | |
520 | void operator()( \ | |
521 | BOOST_ASIO_MOVE_ARG(Handler) handler, \ | |
522 | BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) \ | |
523 | { \ | |
524 | BOOST_ASIO_MOVE_CAST(Initiation)(initiation_)( \ | |
525 | detail::redirect_error_handler< \ | |
526 | typename decay<Handler>::type>( \ | |
527 | ec_, BOOST_ASIO_MOVE_CAST(Handler)(handler)), \ | |
528 | BOOST_ASIO_VARIADIC_MOVE_ARGS(n)); \ | |
529 | } \ | |
530 | /**/ | |
531 | BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_INIT_WRAPPER_DEF) | |
532 | #undef BOOST_ASIO_PRIVATE_INIT_WRAPPER_DEF | |
533 | ||
534 | #endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) | |
535 | ||
536 | boost::system::error_code& ec_; | |
537 | Initiation initiation_; | |
538 | }; | |
539 | ||
540 | #if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) | |
541 | ||
542 | template <typename Initiation, typename RawCompletionToken, typename... Args> | |
543 | static return_type initiate( | |
544 | BOOST_ASIO_MOVE_ARG(Initiation) initiation, | |
545 | BOOST_ASIO_MOVE_ARG(RawCompletionToken) token, | |
546 | BOOST_ASIO_MOVE_ARG(Args)... args) | |
11fdf7f2 | 547 | { |
92f5a8d4 TL |
548 | return async_initiate<CompletionToken, |
549 | typename detail::redirect_error_signature<Signature>::type>( | |
550 | init_wrapper<typename decay<Initiation>::type>( | |
551 | token.ec_, BOOST_ASIO_MOVE_CAST(Initiation)(initiation)), | |
552 | token.token_, BOOST_ASIO_MOVE_CAST(Args)(args)...); | |
553 | } | |
554 | ||
555 | #else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) | |
556 | ||
557 | template <typename Initiation, typename RawCompletionToken> | |
558 | static return_type initiate( | |
559 | BOOST_ASIO_MOVE_ARG(Initiation) initiation, | |
560 | BOOST_ASIO_MOVE_ARG(RawCompletionToken) token) | |
561 | { | |
562 | return async_initiate<CompletionToken, | |
563 | typename detail::redirect_error_signature<Signature>::type>( | |
564 | init_wrapper<typename decay<Initiation>::type>( | |
565 | token.ec_, BOOST_ASIO_MOVE_CAST(Initiation)(initiation)), | |
566 | token.token_); | |
11fdf7f2 | 567 | } |
11fdf7f2 | 568 | |
92f5a8d4 TL |
569 | #define BOOST_ASIO_PRIVATE_INITIATE_DEF(n) \ |
570 | template <typename Initiation, typename RawCompletionToken, \ | |
571 | BOOST_ASIO_VARIADIC_TPARAMS(n)> \ | |
572 | static return_type initiate( \ | |
573 | BOOST_ASIO_MOVE_ARG(Initiation) initiation, \ | |
574 | BOOST_ASIO_MOVE_ARG(RawCompletionToken) token, \ | |
575 | BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) \ | |
576 | { \ | |
577 | return async_initiate<CompletionToken, \ | |
578 | typename detail::redirect_error_signature<Signature>::type>( \ | |
579 | init_wrapper<typename decay<Initiation>::type>( \ | |
580 | token.ec_, BOOST_ASIO_MOVE_CAST(Initiation)(initiation)), \ | |
581 | token.token_, BOOST_ASIO_VARIADIC_MOVE_ARGS(n)); \ | |
582 | } \ | |
583 | /**/ | |
584 | BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_INITIATE_DEF) | |
585 | #undef BOOST_ASIO_PRIVATE_INITIATE_DEF | |
586 | ||
587 | #endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) | |
588 | }; | |
11fdf7f2 | 589 | |
1e59de90 TL |
590 | template <template <typename, typename> class Associator, |
591 | typename Handler, typename DefaultCandidate> | |
592 | struct associator<Associator, | |
593 | detail::redirect_error_handler<Handler>, DefaultCandidate> | |
594 | : Associator<Handler, DefaultCandidate> | |
11fdf7f2 | 595 | { |
1e59de90 | 596 | static typename Associator<Handler, DefaultCandidate>::type get( |
92f5a8d4 | 597 | const detail::redirect_error_handler<Handler>& h, |
1e59de90 | 598 | const DefaultCandidate& c = DefaultCandidate()) BOOST_ASIO_NOEXCEPT |
11fdf7f2 | 599 | { |
1e59de90 | 600 | return Associator<Handler, DefaultCandidate>::get(h.handler_, c); |
11fdf7f2 TL |
601 | } |
602 | }; | |
603 | ||
604 | #endif // !defined(GENERATING_DOCUMENTATION) | |
605 | ||
606 | } // namespace asio | |
607 | } // namespace boost | |
608 | ||
609 | #include <boost/asio/detail/pop_options.hpp> | |
610 | ||
92f5a8d4 | 611 | #endif // BOOST_ASIO_IMPL_REDIRECT_ERROR_HPP |