]>
Commit | Line | Data |
---|---|---|
b32b8144 FG |
1 | // |
2 | // impl/post.hpp | |
3 | // ~~~~~~~~~~~~~ | |
4 | // | |
92f5a8d4 | 5 | // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) |
b32b8144 FG |
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_IMPL_POST_HPP | |
12 | #define BOOST_ASIO_IMPL_POST_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_allocator.hpp> | |
20 | #include <boost/asio/associated_executor.hpp> | |
21 | #include <boost/asio/detail/work_dispatcher.hpp> | |
22 | ||
23 | #include <boost/asio/detail/push_options.hpp> | |
24 | ||
25 | namespace boost { | |
26 | namespace asio { | |
92f5a8d4 | 27 | namespace detail { |
b32b8144 | 28 | |
92f5a8d4 | 29 | class initiate_post |
b32b8144 | 30 | { |
92f5a8d4 TL |
31 | public: |
32 | template <typename CompletionHandler> | |
33 | void operator()(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler) const | |
34 | { | |
35 | typedef typename decay<CompletionHandler>::type DecayedHandler; | |
b32b8144 | 36 | |
92f5a8d4 TL |
37 | typename associated_executor<DecayedHandler>::type ex( |
38 | (get_associated_executor)(handler)); | |
b32b8144 | 39 | |
92f5a8d4 TL |
40 | typename associated_allocator<DecayedHandler>::type alloc( |
41 | (get_associated_allocator)(handler)); | |
b32b8144 | 42 | |
92f5a8d4 TL |
43 | ex.post(BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler), alloc); |
44 | } | |
45 | }; | |
b32b8144 | 46 | |
92f5a8d4 TL |
47 | template <typename Executor> |
48 | class initiate_post_with_executor | |
49 | { | |
50 | public: | |
51 | typedef Executor executor_type; | |
b32b8144 | 52 | |
92f5a8d4 TL |
53 | explicit initiate_post_with_executor(const Executor& ex) |
54 | : ex_(ex) | |
55 | { | |
56 | } | |
b32b8144 | 57 | |
92f5a8d4 TL |
58 | executor_type get_executor() const BOOST_ASIO_NOEXCEPT |
59 | { | |
60 | return ex_; | |
61 | } | |
62 | ||
63 | template <typename CompletionHandler> | |
64 | void operator()(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler) const | |
65 | { | |
66 | typedef typename decay<CompletionHandler>::type DecayedHandler; | |
67 | ||
68 | typename associated_allocator<DecayedHandler>::type alloc( | |
69 | (get_associated_allocator)(handler)); | |
b32b8144 | 70 | |
92f5a8d4 TL |
71 | ex_.post(detail::work_dispatcher<DecayedHandler>( |
72 | BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler)), alloc); | |
73 | } | |
b32b8144 | 74 | |
92f5a8d4 TL |
75 | private: |
76 | Executor ex_; | |
77 | }; | |
b32b8144 | 78 | |
92f5a8d4 | 79 | } // namespace detail |
b32b8144 | 80 | |
92f5a8d4 TL |
81 | template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) CompletionToken> |
82 | BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void()) post( | |
83 | BOOST_ASIO_MOVE_ARG(CompletionToken) token) | |
84 | { | |
85 | return async_initiate<CompletionToken, void()>( | |
86 | detail::initiate_post(), token); | |
87 | } | |
88 | ||
89 | template <typename Executor, | |
90 | BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) CompletionToken> | |
91 | BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void()) post( | |
92 | const Executor& ex, BOOST_ASIO_MOVE_ARG(CompletionToken) token, | |
93 | typename enable_if<is_executor<Executor>::value>::type*) | |
94 | { | |
95 | return async_initiate<CompletionToken, void()>( | |
96 | detail::initiate_post_with_executor<Executor>(ex), token); | |
b32b8144 FG |
97 | } |
98 | ||
92f5a8d4 TL |
99 | template <typename ExecutionContext, |
100 | BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) CompletionToken> | |
101 | inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void()) post( | |
b32b8144 FG |
102 | ExecutionContext& ctx, BOOST_ASIO_MOVE_ARG(CompletionToken) token, |
103 | typename enable_if<is_convertible< | |
104 | ExecutionContext&, execution_context&>::value>::type*) | |
105 | { | |
106 | return (post)(ctx.get_executor(), | |
107 | BOOST_ASIO_MOVE_CAST(CompletionToken)(token)); | |
108 | } | |
109 | ||
110 | } // namespace asio | |
111 | } // namespace boost | |
112 | ||
113 | #include <boost/asio/detail/pop_options.hpp> | |
114 | ||
115 | #endif // BOOST_ASIO_IMPL_POST_HPP |