123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415 |
- //
- // async_ops.hpp
- // ~~~~~~~~~~~~~
- //
- // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
- //
- // Distributed under the Boost Software License, Version 1.0. (See accompanying
- // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
- //
- #ifndef ARCHETYPES_ASYNC_OPS_HPP
- #define ARCHETYPES_ASYNC_OPS_HPP
- #include <boost/asio/associated_allocator.hpp>
- #include <boost/asio/associated_executor.hpp>
- #include <boost/asio/async_result.hpp>
- #include <boost/asio/error.hpp>
- #if defined(BOOST_ASIO_HAS_BOOST_BIND)
- # include <boost/bind.hpp>
- #else // defined(BOOST_ASIO_HAS_BOOST_BIND)
- # include <functional>
- #endif // defined(BOOST_ASIO_HAS_BOOST_BIND)
- namespace archetypes {
- #if defined(BOOST_ASIO_HAS_BOOST_BIND)
- namespace bindns = boost;
- #else // defined(BOOST_ASIO_HAS_BOOST_BIND)
- namespace bindns = std;
- #endif // defined(BOOST_ASIO_HAS_BOOST_BIND)
- template <typename CompletionToken>
- BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void())
- async_op_0(BOOST_ASIO_MOVE_ARG(CompletionToken) token)
- {
- typedef typename boost::asio::async_completion<CompletionToken,
- void()>::completion_handler_type handler_type;
- boost::asio::async_completion<CompletionToken,
- void()> completion(token);
- typename boost::asio::associated_allocator<handler_type>::type a
- = boost::asio::get_associated_allocator(completion.completion_handler);
- typename boost::asio::associated_executor<handler_type>::type ex
- = boost::asio::get_associated_executor(completion.completion_handler);
- ex.post(BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler), a);
- return completion.result.get();
- }
- template <typename CompletionToken>
- BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void(boost::system::error_code))
- async_op_ec_0(bool ok, BOOST_ASIO_MOVE_ARG(CompletionToken) token)
- {
- typedef typename boost::asio::async_completion<CompletionToken,
- void(boost::system::error_code)>::completion_handler_type handler_type;
- boost::asio::async_completion<CompletionToken,
- void(boost::system::error_code)> completion(token);
- typename boost::asio::associated_allocator<handler_type>::type a
- = boost::asio::get_associated_allocator(completion.completion_handler);
- typename boost::asio::associated_executor<handler_type>::type ex
- = boost::asio::get_associated_executor(completion.completion_handler);
- if (ok)
- {
- ex.post(
- bindns::bind(
- BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
- boost::system::error_code()), a);
- }
- else
- {
- ex.post(
- bindns::bind(
- BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
- boost::system::error_code(boost::asio::error::operation_aborted)), a);
- }
- return completion.result.get();
- }
- template <typename CompletionToken>
- BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void(std::exception_ptr))
- async_op_ex_0(bool ok, BOOST_ASIO_MOVE_ARG(CompletionToken) token)
- {
- typedef typename boost::asio::async_completion<CompletionToken,
- void(std::exception_ptr)>::completion_handler_type handler_type;
- boost::asio::async_completion<CompletionToken,
- void(std::exception_ptr)> completion(token);
- typename boost::asio::associated_allocator<handler_type>::type a
- = boost::asio::get_associated_allocator(completion.completion_handler);
- typename boost::asio::associated_executor<handler_type>::type ex
- = boost::asio::get_associated_executor(completion.completion_handler);
- if (ok)
- {
- ex.post(
- bindns::bind(
- BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
- std::exception_ptr()), a);
- }
- else
- {
- ex.post(
- bindns::bind(
- BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
- std::make_exception_ptr(std::runtime_error("blah"))), a);
- }
- return completion.result.get();
- }
- template <typename CompletionToken>
- BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void(int))
- async_op_1(BOOST_ASIO_MOVE_ARG(CompletionToken) token)
- {
- typedef typename boost::asio::async_completion<CompletionToken,
- void(int)>::completion_handler_type handler_type;
- boost::asio::async_completion<CompletionToken,
- void(int)> completion(token);
- typename boost::asio::associated_allocator<handler_type>::type a
- = boost::asio::get_associated_allocator(completion.completion_handler);
- typename boost::asio::associated_executor<handler_type>::type ex
- = boost::asio::get_associated_executor(completion.completion_handler);
- ex.post(
- bindns::bind(
- BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
- 42), a);
- return completion.result.get();
- }
- template <typename CompletionToken>
- BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken,
- void(boost::system::error_code, int))
- async_op_ec_1(bool ok, BOOST_ASIO_MOVE_ARG(CompletionToken) token)
- {
- typedef typename boost::asio::async_completion<CompletionToken,
- void(boost::system::error_code, int)>::completion_handler_type
- handler_type;
- boost::asio::async_completion<CompletionToken,
- void(boost::system::error_code, int)> completion(token);
- typename boost::asio::associated_allocator<handler_type>::type a
- = boost::asio::get_associated_allocator(completion.completion_handler);
- typename boost::asio::associated_executor<handler_type>::type ex
- = boost::asio::get_associated_executor(completion.completion_handler);
- if (ok)
- {
- ex.post(
- bindns::bind(
- BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
- boost::system::error_code(), 42), a);
- }
- else
- {
- ex.post(
- bindns::bind(
- BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
- boost::system::error_code(boost::asio::error::operation_aborted),
- 0), a);
- }
- return completion.result.get();
- }
- template <typename CompletionToken>
- BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void(std::exception_ptr, int))
- async_op_ex_1(bool ok, BOOST_ASIO_MOVE_ARG(CompletionToken) token)
- {
- typedef typename boost::asio::async_completion<CompletionToken,
- void(std::exception_ptr, int)>::completion_handler_type
- handler_type;
- boost::asio::async_completion<CompletionToken,
- void(std::exception_ptr, int)> completion(token);
- typename boost::asio::associated_allocator<handler_type>::type a
- = boost::asio::get_associated_allocator(completion.completion_handler);
- typename boost::asio::associated_executor<handler_type>::type ex
- = boost::asio::get_associated_executor(completion.completion_handler);
- if (ok)
- {
- ex.post(
- bindns::bind(
- BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
- std::exception_ptr(), 42), a);
- }
- else
- {
- ex.post(
- bindns::bind(
- BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
- std::make_exception_ptr(std::runtime_error("blah")), 0), a);
- }
- return completion.result.get();
- }
- template <typename CompletionToken>
- BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void(int, double))
- async_op_2(BOOST_ASIO_MOVE_ARG(CompletionToken) token)
- {
- typedef typename boost::asio::async_completion<CompletionToken,
- void(int, double)>::completion_handler_type handler_type;
- boost::asio::async_completion<CompletionToken,
- void(int, double)> completion(token);
- typename boost::asio::associated_allocator<handler_type>::type a
- = boost::asio::get_associated_allocator(completion.completion_handler);
- typename boost::asio::associated_executor<handler_type>::type ex
- = boost::asio::get_associated_executor(completion.completion_handler);
- ex.post(
- bindns::bind(
- BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
- 42, 2.0), a);
- return completion.result.get();
- }
- template <typename CompletionToken>
- BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken,
- void(boost::system::error_code, int, double))
- async_op_ec_2(bool ok, BOOST_ASIO_MOVE_ARG(CompletionToken) token)
- {
- typedef typename boost::asio::async_completion<CompletionToken,
- void(boost::system::error_code, int, double)>::completion_handler_type
- handler_type;
- boost::asio::async_completion<CompletionToken,
- void(boost::system::error_code, int, double)> completion(token);
- typename boost::asio::associated_allocator<handler_type>::type a
- = boost::asio::get_associated_allocator(completion.completion_handler);
- typename boost::asio::associated_executor<handler_type>::type ex
- = boost::asio::get_associated_executor(completion.completion_handler);
- if (ok)
- {
- ex.post(
- bindns::bind(
- BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
- boost::system::error_code(), 42, 2.0), a);
- }
- else
- {
- ex.post(
- bindns::bind(
- BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
- boost::system::error_code(boost::asio::error::operation_aborted),
- 0, 0.0), a);
- }
- return completion.result.get();
- }
- template <typename CompletionToken>
- BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken,
- void(std::exception_ptr, int, double))
- async_op_ex_2(bool ok, BOOST_ASIO_MOVE_ARG(CompletionToken) token)
- {
- typedef typename boost::asio::async_completion<CompletionToken,
- void(std::exception_ptr, int, double)>::completion_handler_type
- handler_type;
- boost::asio::async_completion<CompletionToken,
- void(std::exception_ptr, int, double)> completion(token);
- typename boost::asio::associated_allocator<handler_type>::type a
- = boost::asio::get_associated_allocator(completion.completion_handler);
- typename boost::asio::associated_executor<handler_type>::type ex
- = boost::asio::get_associated_executor(completion.completion_handler);
- if (ok)
- {
- ex.post(
- bindns::bind(
- BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
- std::exception_ptr(), 42, 2.0), a);
- }
- else
- {
- ex.post(
- bindns::bind(
- BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
- std::make_exception_ptr(std::runtime_error("blah")), 0, 0.0), a);
- }
- return completion.result.get();
- }
- template <typename CompletionToken>
- BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void(int, double, char))
- async_op_3(BOOST_ASIO_MOVE_ARG(CompletionToken) token)
- {
- typedef typename boost::asio::async_completion<CompletionToken,
- void(int, double, char)>::completion_handler_type handler_type;
- boost::asio::async_completion<CompletionToken,
- void(int, double, char)> completion(token);
- typename boost::asio::associated_allocator<handler_type>::type a
- = boost::asio::get_associated_allocator(completion.completion_handler);
- typename boost::asio::associated_executor<handler_type>::type ex
- = boost::asio::get_associated_executor(completion.completion_handler);
- ex.post(
- bindns::bind(
- BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
- 42, 2.0, 'a'), a);
- return completion.result.get();
- }
- template <typename CompletionToken>
- BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken,
- void(boost::system::error_code, int, double, char))
- async_op_ec_3(bool ok, BOOST_ASIO_MOVE_ARG(CompletionToken) token)
- {
- typedef typename boost::asio::async_completion<CompletionToken,
- void(boost::system::error_code, int, double, char)>::completion_handler_type
- handler_type;
- boost::asio::async_completion<CompletionToken,
- void(boost::system::error_code, int, double, char)> completion(token);
- typename boost::asio::associated_allocator<handler_type>::type a
- = boost::asio::get_associated_allocator(completion.completion_handler);
- typename boost::asio::associated_executor<handler_type>::type ex
- = boost::asio::get_associated_executor(completion.completion_handler);
- if (ok)
- {
- ex.post(
- bindns::bind(
- BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
- boost::system::error_code(), 42, 2.0, 'a'), a);
- }
- else
- {
- ex.post(
- bindns::bind(
- BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
- boost::system::error_code(boost::asio::error::operation_aborted),
- 0, 0.0, 'z'), a);
- }
- return completion.result.get();
- }
- template <typename CompletionToken>
- BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken,
- void(std::exception_ptr, int, double, char))
- async_op_ex_3(bool ok, BOOST_ASIO_MOVE_ARG(CompletionToken) token)
- {
- typedef typename boost::asio::async_completion<CompletionToken,
- void(std::exception_ptr, int, double, char)>::completion_handler_type
- handler_type;
- boost::asio::async_completion<CompletionToken,
- void(std::exception_ptr, int, double, char)> completion(token);
- typename boost::asio::associated_allocator<handler_type>::type a
- = boost::asio::get_associated_allocator(completion.completion_handler);
- typename boost::asio::associated_executor<handler_type>::type ex
- = boost::asio::get_associated_executor(completion.completion_handler);
- if (ok)
- {
- ex.post(
- bindns::bind(
- BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
- std::exception_ptr(), 42, 2.0, 'a'), a);
- }
- else
- {
- ex.post(
- bindns::bind(
- BOOST_ASIO_MOVE_CAST(handler_type)(completion.completion_handler),
- std::make_exception_ptr(std::runtime_error("blah")),
- 0, 0.0, 'z'), a);
- }
- return completion.result.get();
- }
- } // namespace archetypes
- #endif // ARCHETYPES_ASYNC_OPS_HPP
|