5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef ARCHETYPES_ASYNC_OPS_HPP
12 #define ARCHETYPES_ASYNC_OPS_HPP
14 #include <boost/asio/associated_allocator.hpp>
15 #include <boost/asio/associated_executor.hpp>
16 #include <boost/asio/async_result.hpp>
17 #include <boost/asio/error.hpp>
19 #if defined(BOOST_ASIO_HAS_BOOST_BIND)
20 # include <boost/bind.hpp>
21 #else // defined(BOOST_ASIO_HAS_BOOST_BIND)
22 # include <functional>
23 #endif // defined(BOOST_ASIO_HAS_BOOST_BIND)
25 namespace archetypes {
27 #if defined(BOOST_ASIO_HAS_BOOST_BIND)
28 namespace bindns = boost;
29 #else // defined(BOOST_ASIO_HAS_BOOST_BIND)
30 namespace bindns = std;
31 #endif // defined(BOOST_ASIO_HAS_BOOST_BIND)
33 template <typename CompletionToken>
34 BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void())
35 async_op_0(BOOST_ASIO_MOVE_ARG(CompletionToken) token)
37 typedef typename boost::asio::async_completion<CompletionToken,
38 void()>::completion_handler_type handler_type;
40 boost::asio::async_completion<CompletionToken,
41 void()> completion(token);
43 typename boost::asio::associated_allocator<handler_type>::type a
44 = boost::asio::get_associated_allocator(completion.completion_handler);
46 typename boost::asio::associated_executor<handler_type>::type ex
47 = boost::asio::get_associated_executor(completion.completion_handler);
49 ex.post(BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler), a);
51 return completion.result.get();
54 template <typename CompletionToken>
55 BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void(boost::system::error_code))
56 async_op_ec_0(bool ok, BOOST_ASIO_MOVE_ARG(CompletionToken) token)
58 typedef typename boost::asio::async_completion<CompletionToken,
59 void(boost::system::error_code)>::completion_handler_type handler_type;
61 boost::asio::async_completion<CompletionToken,
62 void(boost::system::error_code)> completion(token);
64 typename boost::asio::associated_allocator<handler_type>::type a
65 = boost::asio::get_associated_allocator(completion.completion_handler);
67 typename boost::asio::associated_executor<handler_type>::type ex
68 = boost::asio::get_associated_executor(completion.completion_handler);
74 BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
75 boost::system::error_code()), a);
81 BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
82 boost::system::error_code(boost::asio::error::operation_aborted)), a);
85 return completion.result.get();
88 template <typename CompletionToken>
89 BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void(std::exception_ptr))
90 async_op_ex_0(bool ok, BOOST_ASIO_MOVE_ARG(CompletionToken) token)
92 typedef typename boost::asio::async_completion<CompletionToken,
93 void(std::exception_ptr)>::completion_handler_type handler_type;
95 boost::asio::async_completion<CompletionToken,
96 void(std::exception_ptr)> completion(token);
98 typename boost::asio::associated_allocator<handler_type>::type a
99 = boost::asio::get_associated_allocator(completion.completion_handler);
101 typename boost::asio::associated_executor<handler_type>::type ex
102 = boost::asio::get_associated_executor(completion.completion_handler);
108 BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
109 std::exception_ptr()), a);
115 BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
116 std::make_exception_ptr(std::runtime_error("blah"))), a);
119 return completion.result.get();
122 template <typename CompletionToken>
123 BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void(int))
124 async_op_1(BOOST_ASIO_MOVE_ARG(CompletionToken) token)
126 typedef typename boost::asio::async_completion<CompletionToken,
127 void(int)>::completion_handler_type handler_type;
129 boost::asio::async_completion<CompletionToken,
130 void(int)> completion(token);
132 typename boost::asio::associated_allocator<handler_type>::type a
133 = boost::asio::get_associated_allocator(completion.completion_handler);
135 typename boost::asio::associated_executor<handler_type>::type ex
136 = boost::asio::get_associated_executor(completion.completion_handler);
140 BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
143 return completion.result.get();
146 template <typename CompletionToken>
147 BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken,
148 void(boost::system::error_code, int))
149 async_op_ec_1(bool ok, BOOST_ASIO_MOVE_ARG(CompletionToken) token)
151 typedef typename boost::asio::async_completion<CompletionToken,
152 void(boost::system::error_code, int)>::completion_handler_type
155 boost::asio::async_completion<CompletionToken,
156 void(boost::system::error_code, int)> completion(token);
158 typename boost::asio::associated_allocator<handler_type>::type a
159 = boost::asio::get_associated_allocator(completion.completion_handler);
161 typename boost::asio::associated_executor<handler_type>::type ex
162 = boost::asio::get_associated_executor(completion.completion_handler);
168 BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
169 boost::system::error_code(), 42), a);
175 BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
176 boost::system::error_code(boost::asio::error::operation_aborted),
180 return completion.result.get();
183 template <typename CompletionToken>
184 BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void(std::exception_ptr, int))
185 async_op_ex_1(bool ok, BOOST_ASIO_MOVE_ARG(CompletionToken) token)
187 typedef typename boost::asio::async_completion<CompletionToken,
188 void(std::exception_ptr, int)>::completion_handler_type
191 boost::asio::async_completion<CompletionToken,
192 void(std::exception_ptr, int)> completion(token);
194 typename boost::asio::associated_allocator<handler_type>::type a
195 = boost::asio::get_associated_allocator(completion.completion_handler);
197 typename boost::asio::associated_executor<handler_type>::type ex
198 = boost::asio::get_associated_executor(completion.completion_handler);
204 BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
205 std::exception_ptr(), 42), a);
211 BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
212 std::make_exception_ptr(std::runtime_error("blah")), 0), a);
215 return completion.result.get();
218 template <typename CompletionToken>
219 BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void(int, double))
220 async_op_2(BOOST_ASIO_MOVE_ARG(CompletionToken) token)
222 typedef typename boost::asio::async_completion<CompletionToken,
223 void(int, double)>::completion_handler_type handler_type;
225 boost::asio::async_completion<CompletionToken,
226 void(int, double)> completion(token);
228 typename boost::asio::associated_allocator<handler_type>::type a
229 = boost::asio::get_associated_allocator(completion.completion_handler);
231 typename boost::asio::associated_executor<handler_type>::type ex
232 = boost::asio::get_associated_executor(completion.completion_handler);
236 BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
239 return completion.result.get();
242 template <typename CompletionToken>
243 BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken,
244 void(boost::system::error_code, int, double))
245 async_op_ec_2(bool ok, BOOST_ASIO_MOVE_ARG(CompletionToken) token)
247 typedef typename boost::asio::async_completion<CompletionToken,
248 void(boost::system::error_code, int, double)>::completion_handler_type
251 boost::asio::async_completion<CompletionToken,
252 void(boost::system::error_code, int, double)> completion(token);
254 typename boost::asio::associated_allocator<handler_type>::type a
255 = boost::asio::get_associated_allocator(completion.completion_handler);
257 typename boost::asio::associated_executor<handler_type>::type ex
258 = boost::asio::get_associated_executor(completion.completion_handler);
264 BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
265 boost::system::error_code(), 42, 2.0), a);
271 BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
272 boost::system::error_code(boost::asio::error::operation_aborted),
276 return completion.result.get();
279 template <typename CompletionToken>
280 BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken,
281 void(std::exception_ptr, int, double))
282 async_op_ex_2(bool ok, BOOST_ASIO_MOVE_ARG(CompletionToken) token)
284 typedef typename boost::asio::async_completion<CompletionToken,
285 void(std::exception_ptr, int, double)>::completion_handler_type
288 boost::asio::async_completion<CompletionToken,
289 void(std::exception_ptr, int, double)> completion(token);
291 typename boost::asio::associated_allocator<handler_type>::type a
292 = boost::asio::get_associated_allocator(completion.completion_handler);
294 typename boost::asio::associated_executor<handler_type>::type ex
295 = boost::asio::get_associated_executor(completion.completion_handler);
301 BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
302 std::exception_ptr(), 42, 2.0), a);
308 BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
309 std::make_exception_ptr(std::runtime_error("blah")), 0, 0.0), a);
312 return completion.result.get();
315 template <typename CompletionToken>
316 BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void(int, double, char))
317 async_op_3(BOOST_ASIO_MOVE_ARG(CompletionToken) token)
319 typedef typename boost::asio::async_completion<CompletionToken,
320 void(int, double, char)>::completion_handler_type handler_type;
322 boost::asio::async_completion<CompletionToken,
323 void(int, double, char)> completion(token);
325 typename boost::asio::associated_allocator<handler_type>::type a
326 = boost::asio::get_associated_allocator(completion.completion_handler);
328 typename boost::asio::associated_executor<handler_type>::type ex
329 = boost::asio::get_associated_executor(completion.completion_handler);
333 BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
336 return completion.result.get();
339 template <typename CompletionToken>
340 BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken,
341 void(boost::system::error_code, int, double, char))
342 async_op_ec_3(bool ok, BOOST_ASIO_MOVE_ARG(CompletionToken) token)
344 typedef typename boost::asio::async_completion<CompletionToken,
345 void(boost::system::error_code, int, double, char)>::completion_handler_type
348 boost::asio::async_completion<CompletionToken,
349 void(boost::system::error_code, int, double, char)> completion(token);
351 typename boost::asio::associated_allocator<handler_type>::type a
352 = boost::asio::get_associated_allocator(completion.completion_handler);
354 typename boost::asio::associated_executor<handler_type>::type ex
355 = boost::asio::get_associated_executor(completion.completion_handler);
361 BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
362 boost::system::error_code(), 42, 2.0, 'a'), a);
368 BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
369 boost::system::error_code(boost::asio::error::operation_aborted),
373 return completion.result.get();
376 template <typename CompletionToken>
377 BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken,
378 void(std::exception_ptr, int, double, char))
379 async_op_ex_3(bool ok, BOOST_ASIO_MOVE_ARG(CompletionToken) token)
381 typedef typename boost::asio::async_completion<CompletionToken,
382 void(std::exception_ptr, int, double, char)>::completion_handler_type
385 boost::asio::async_completion<CompletionToken,
386 void(std::exception_ptr, int, double, char)> completion(token);
388 typename boost::asio::associated_allocator<handler_type>::type a
389 = boost::asio::get_associated_allocator(completion.completion_handler);
391 typename boost::asio::associated_executor<handler_type>::type ex
392 = boost::asio::get_associated_executor(completion.completion_handler);
398 BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
399 std::exception_ptr(), 42, 2.0, 'a'), a);
405 BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
406 std::make_exception_ptr(std::runtime_error("blah")),
410 return completion.result.get();
413 } // namespace archetypes
415 #endif // ARCHETYPES_ASYNC_OPS_HPP