File indexing completed on 2025-01-18 09:28:51
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_SEND_FUNCTIONS_HPP
0012 #define BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_SEND_FUNCTIONS_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019 #include <boost/asio/async_result.hpp>
0020 #include <boost/asio/detail/type_traits.hpp>
0021 #include <boost/system/error_code.hpp>
0022 #include <boost/asio/experimental/detail/channel_message.hpp>
0023
0024 #include <boost/asio/detail/push_options.hpp>
0025
0026 namespace boost {
0027 namespace asio {
0028 namespace experimental {
0029 namespace detail {
0030
0031 template <typename Derived, typename Executor, typename... Signatures>
0032 class channel_send_functions;
0033
0034 template <typename Derived, typename Executor, typename R, typename... Args>
0035 class channel_send_functions<Derived, Executor, R(Args...)>
0036 {
0037 public:
0038 template <typename... Args2>
0039 enable_if_t<
0040 is_constructible<detail::channel_message<R(Args...)>, int, Args2...>::value,
0041 bool
0042 > try_send(Args2&&... args)
0043 {
0044 typedef typename detail::channel_message<R(Args...)> message_type;
0045 Derived* self = static_cast<Derived*>(this);
0046 return self->service_->template try_send<message_type>(
0047 self->impl_, false, static_cast<Args2&&>(args)...);
0048 }
0049
0050 template <typename... Args2>
0051 enable_if_t<
0052 is_constructible<detail::channel_message<R(Args...)>, int, Args2...>::value,
0053 bool
0054 > try_send_via_dispatch(Args2&&... args)
0055 {
0056 typedef typename detail::channel_message<R(Args...)> message_type;
0057 Derived* self = static_cast<Derived*>(this);
0058 return self->service_->template try_send<message_type>(
0059 self->impl_, true, static_cast<Args2&&>(args)...);
0060 }
0061
0062 template <typename... Args2>
0063 enable_if_t<
0064 is_constructible<detail::channel_message<R(Args...)>, int, Args2...>::value,
0065 std::size_t
0066 > try_send_n(std::size_t count, Args2&&... args)
0067 {
0068 typedef typename detail::channel_message<R(Args...)> message_type;
0069 Derived* self = static_cast<Derived*>(this);
0070 return self->service_->template try_send_n<message_type>(
0071 self->impl_, count, false, static_cast<Args2&&>(args)...);
0072 }
0073
0074 template <typename... Args2>
0075 enable_if_t<
0076 is_constructible<detail::channel_message<R(Args...)>, int, Args2...>::value,
0077 std::size_t
0078 > try_send_n_via_dispatch(std::size_t count, Args2&&... args)
0079 {
0080 typedef typename detail::channel_message<R(Args...)> message_type;
0081 Derived* self = static_cast<Derived*>(this);
0082 return self->service_->template try_send_n<message_type>(
0083 self->impl_, count, true, static_cast<Args2&&>(args)...);
0084 }
0085
0086 template <
0087 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code))
0088 CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(Executor)>
0089 auto async_send(Args... args,
0090 CompletionToken&& token
0091 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(Executor))
0092 -> decltype(
0093 async_initiate<CompletionToken, void (boost::system::error_code)>(
0094 declval<typename conditional_t<false, CompletionToken,
0095 Derived>::initiate_async_send>(), token,
0096 declval<typename conditional_t<false, CompletionToken,
0097 Derived>::payload_type>()))
0098 {
0099 typedef typename Derived::payload_type payload_type;
0100 typedef typename detail::channel_message<R(Args...)> message_type;
0101 Derived* self = static_cast<Derived*>(this);
0102 return async_initiate<CompletionToken, void (boost::system::error_code)>(
0103 typename Derived::initiate_async_send(self), token,
0104 payload_type(message_type(0, static_cast<Args&&>(args)...)));
0105 }
0106 };
0107
0108 template <typename Derived, typename Executor,
0109 typename R, typename... Args, typename... Signatures>
0110 class channel_send_functions<Derived, Executor, R(Args...), Signatures...> :
0111 public channel_send_functions<Derived, Executor, Signatures...>
0112 {
0113 public:
0114 using channel_send_functions<Derived, Executor, Signatures...>::try_send;
0115 using channel_send_functions<Derived, Executor, Signatures...>::async_send;
0116
0117 template <typename... Args2>
0118 enable_if_t<
0119 is_constructible<detail::channel_message<R(Args...)>, int, Args2...>::value,
0120 bool
0121 > try_send(Args2&&... args)
0122 {
0123 typedef typename detail::channel_message<R(Args...)> message_type;
0124 Derived* self = static_cast<Derived*>(this);
0125 return self->service_->template try_send<message_type>(
0126 self->impl_, false, static_cast<Args2&&>(args)...);
0127 }
0128
0129 template <typename... Args2>
0130 enable_if_t<
0131 is_constructible<detail::channel_message<R(Args...)>, int, Args2...>::value,
0132 bool
0133 > try_send_via_dispatch(Args2&&... args)
0134 {
0135 typedef typename detail::channel_message<R(Args...)> message_type;
0136 Derived* self = static_cast<Derived*>(this);
0137 return self->service_->template try_send<message_type>(
0138 self->impl_, true, static_cast<Args2&&>(args)...);
0139 }
0140
0141 template <typename... Args2>
0142 enable_if_t<
0143 is_constructible<detail::channel_message<R(Args...)>, int, Args2...>::value,
0144 std::size_t
0145 > try_send_n(std::size_t count, Args2&&... args)
0146 {
0147 typedef typename detail::channel_message<R(Args...)> message_type;
0148 Derived* self = static_cast<Derived*>(this);
0149 return self->service_->template try_send_n<message_type>(
0150 self->impl_, count, false, static_cast<Args2&&>(args)...);
0151 }
0152
0153 template <typename... Args2>
0154 enable_if_t<
0155 is_constructible<detail::channel_message<R(Args...)>, int, Args2...>::value,
0156 std::size_t
0157 > try_send_n_via_dispatch(std::size_t count, Args2&&... args)
0158 {
0159 typedef typename detail::channel_message<R(Args...)> message_type;
0160 Derived* self = static_cast<Derived*>(this);
0161 return self->service_->template try_send_n<message_type>(
0162 self->impl_, count, true, static_cast<Args2&&>(args)...);
0163 }
0164
0165 template <
0166 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code))
0167 CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(Executor)>
0168 auto async_send(Args... args,
0169 CompletionToken&& token
0170 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(Executor))
0171 -> decltype(
0172 async_initiate<CompletionToken, void (boost::system::error_code)>(
0173 declval<typename conditional_t<false, CompletionToken,
0174 Derived>::initiate_async_send>(), token,
0175 declval<typename conditional_t<false, CompletionToken,
0176 Derived>::payload_type>()))
0177 {
0178 typedef typename Derived::payload_type payload_type;
0179 typedef typename detail::channel_message<R(Args...)> message_type;
0180 Derived* self = static_cast<Derived*>(this);
0181 return async_initiate<CompletionToken, void (boost::system::error_code)>(
0182 typename Derived::initiate_async_send(self), token,
0183 payload_type(message_type(0, static_cast<Args&&>(args)...)));
0184 }
0185 };
0186
0187 }
0188 }
0189 }
0190 }
0191
0192 #include <boost/asio/detail/pop_options.hpp>
0193
0194 #endif