2 // experimental/detail/channel_send_functions.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2022 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 BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_SEND_FUNCTIONS_HPP
12 #define BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_SEND_FUNCTIONS_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
19 #include <boost/asio/async_result.hpp>
20 #include <boost/asio/detail/type_traits.hpp>
21 #include <boost/system/error_code.hpp>
22 #include <boost/asio/experimental/detail/channel_message.hpp>
24 #include <boost/asio/detail/push_options.hpp>
28 namespace experimental {
31 template <typename Derived, typename Executor, typename... Signatures>
32 class channel_send_functions;
34 template <typename Derived, typename Executor, typename R, typename... Args>
35 class channel_send_functions<Derived, Executor, R(Args...)>
38 template <typename... Args2>
40 is_constructible<detail::channel_message<R(Args...)>, int, Args2...>::value,
42 >::type try_send(BOOST_ASIO_MOVE_ARG(Args2)... args)
44 typedef typename detail::channel_message<R(Args...)> message_type;
45 Derived* self = static_cast<Derived*>(this);
46 return self->service_->template try_send<message_type>(
47 self->impl_, BOOST_ASIO_MOVE_CAST(Args2)(args)...);
50 template <typename... Args2>
52 is_constructible<detail::channel_message<R(Args...)>, int, Args2...>::value,
54 >::type try_send_n(std::size_t count, BOOST_ASIO_MOVE_ARG(Args2)... args)
56 typedef typename detail::channel_message<R(Args...)> message_type;
57 Derived* self = static_cast<Derived*>(this);
58 return self->service_->template try_send_n<message_type>(
59 self->impl_, count, BOOST_ASIO_MOVE_CAST(Args2)(args)...);
63 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code))
64 CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(Executor)>
65 auto async_send(Args... args,
66 BOOST_ASIO_MOVE_ARG(CompletionToken) token
67 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(Executor))
69 typedef typename Derived::payload_type payload_type;
70 typedef typename detail::channel_message<R(Args...)> message_type;
71 Derived* self = static_cast<Derived*>(this);
72 return async_initiate<CompletionToken, void (boost::system::error_code)>(
73 typename Derived::initiate_async_send(self), token,
74 payload_type(message_type(0, BOOST_ASIO_MOVE_CAST(Args)(args)...)));
78 template <typename Derived, typename Executor,
79 typename R, typename... Args, typename... Signatures>
80 class channel_send_functions<Derived, Executor, R(Args...), Signatures...> :
81 public channel_send_functions<Derived, Executor, Signatures...>
84 using channel_send_functions<Derived, Executor, Signatures...>::try_send;
85 using channel_send_functions<Derived, Executor, Signatures...>::async_send;
87 template <typename... Args2>
89 is_constructible<detail::channel_message<R(Args...)>, int, Args2...>::value,
91 >::type try_send(BOOST_ASIO_MOVE_ARG(Args2)... args)
93 typedef typename detail::channel_message<R(Args...)> message_type;
94 Derived* self = static_cast<Derived*>(this);
95 return self->service_->template try_send<message_type>(
96 self->impl_, BOOST_ASIO_MOVE_CAST(Args2)(args)...);
99 template <typename... Args2>
101 is_constructible<detail::channel_message<R(Args...)>, int, Args2...>::value,
103 >::type try_send_n(std::size_t count, BOOST_ASIO_MOVE_ARG(Args2)... args)
105 typedef typename detail::channel_message<R(Args...)> message_type;
106 Derived* self = static_cast<Derived*>(this);
107 return self->service_->template try_send_n<message_type>(
108 self->impl_, count, BOOST_ASIO_MOVE_CAST(Args2)(args)...);
112 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code))
113 CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(Executor)>
114 auto async_send(Args... args,
115 BOOST_ASIO_MOVE_ARG(CompletionToken) token
116 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(Executor))
118 typedef typename Derived::payload_type payload_type;
119 typedef typename detail::channel_message<R(Args...)> message_type;
120 Derived* self = static_cast<Derived*>(this);
121 return async_initiate<CompletionToken, void (boost::system::error_code)>(
122 typename Derived::initiate_async_send(self), token,
123 payload_type(message_type(0, BOOST_ASIO_MOVE_CAST(Args)(args)...)));
127 } // namespace detail
128 } // namespace experimental
132 #include <boost/asio/detail/pop_options.hpp>
134 #endif // BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_SEND_FUNCTIONS_HPP