File indexing completed on 2025-06-30 08:08:05
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/completion_message.hpp>
0021 #include <boost/asio/detail/type_traits.hpp>
0022 #include <boost/system/error_code.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<boost::asio::detail::completion_message<R(Args...)>,
0041 int, Args2...>::value,
0042 bool
0043 > try_send(Args2&&... args)
0044 {
0045 typedef boost::asio::detail::completion_message<R(Args...)> message_type;
0046 Derived* self = static_cast<Derived*>(this);
0047 return self->service_->template try_send<message_type>(
0048 self->impl_, false, static_cast<Args2&&>(args)...);
0049 }
0050
0051 template <typename... Args2>
0052 enable_if_t<
0053 is_constructible<boost::asio::detail::completion_message<R(Args...)>,
0054 int, Args2...>::value,
0055 bool
0056 > try_send_via_dispatch(Args2&&... args)
0057 {
0058 typedef boost::asio::detail::completion_message<R(Args...)> message_type;
0059 Derived* self = static_cast<Derived*>(this);
0060 return self->service_->template try_send<message_type>(
0061 self->impl_, true, static_cast<Args2&&>(args)...);
0062 }
0063
0064 template <typename... Args2>
0065 enable_if_t<
0066 is_constructible<boost::asio::detail::completion_message<R(Args...)>,
0067 int, Args2...>::value,
0068 std::size_t
0069 > try_send_n(std::size_t count, Args2&&... args)
0070 {
0071 typedef boost::asio::detail::completion_message<R(Args...)> message_type;
0072 Derived* self = static_cast<Derived*>(this);
0073 return self->service_->template try_send_n<message_type>(
0074 self->impl_, count, false, static_cast<Args2&&>(args)...);
0075 }
0076
0077 template <typename... Args2>
0078 enable_if_t<
0079 is_constructible<boost::asio::detail::completion_message<R(Args...)>,
0080 int, Args2...>::value,
0081 std::size_t
0082 > try_send_n_via_dispatch(std::size_t count, Args2&&... args)
0083 {
0084 typedef boost::asio::detail::completion_message<R(Args...)> message_type;
0085 Derived* self = static_cast<Derived*>(this);
0086 return self->service_->template try_send_n<message_type>(
0087 self->impl_, count, true, static_cast<Args2&&>(args)...);
0088 }
0089
0090 template <
0091 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code))
0092 CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(Executor)>
0093 auto async_send(Args... args,
0094 CompletionToken&& token
0095 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(Executor))
0096 -> decltype(
0097 async_initiate<CompletionToken, void (boost::system::error_code)>(
0098 declval<typename conditional_t<false, CompletionToken,
0099 Derived>::initiate_async_send>(), token,
0100 declval<typename conditional_t<false, CompletionToken,
0101 Derived>::payload_type>()))
0102 {
0103 typedef typename Derived::payload_type payload_type;
0104 typedef boost::asio::detail::completion_message<R(Args...)> message_type;
0105 Derived* self = static_cast<Derived*>(this);
0106 return async_initiate<CompletionToken, void (boost::system::error_code)>(
0107 typename Derived::initiate_async_send(self), token,
0108 payload_type(message_type(0, static_cast<Args&&>(args)...)));
0109 }
0110 };
0111
0112 template <typename Derived, typename Executor,
0113 typename R, typename... Args, typename... Signatures>
0114 class channel_send_functions<Derived, Executor, R(Args...), Signatures...> :
0115 public channel_send_functions<Derived, Executor, Signatures...>
0116 {
0117 public:
0118 using channel_send_functions<Derived, Executor, Signatures...>::try_send;
0119 using channel_send_functions<Derived, Executor, Signatures...>::async_send;
0120
0121 template <typename... Args2>
0122 enable_if_t<
0123 is_constructible<boost::asio::detail::completion_message<R(Args...)>,
0124 int, Args2...>::value,
0125 bool
0126 > try_send(Args2&&... args)
0127 {
0128 typedef boost::asio::detail::completion_message<R(Args...)> message_type;
0129 Derived* self = static_cast<Derived*>(this);
0130 return self->service_->template try_send<message_type>(
0131 self->impl_, false, static_cast<Args2&&>(args)...);
0132 }
0133
0134 template <typename... Args2>
0135 enable_if_t<
0136 is_constructible<boost::asio::detail::completion_message<R(Args...)>,
0137 int, Args2...>::value,
0138 bool
0139 > try_send_via_dispatch(Args2&&... args)
0140 {
0141 typedef boost::asio::detail::completion_message<R(Args...)> message_type;
0142 Derived* self = static_cast<Derived*>(this);
0143 return self->service_->template try_send<message_type>(
0144 self->impl_, true, static_cast<Args2&&>(args)...);
0145 }
0146
0147 template <typename... Args2>
0148 enable_if_t<
0149 is_constructible<boost::asio::detail::completion_message<R(Args...)>,
0150 int, Args2...>::value,
0151 std::size_t
0152 > try_send_n(std::size_t count, Args2&&... args)
0153 {
0154 typedef boost::asio::detail::completion_message<R(Args...)> message_type;
0155 Derived* self = static_cast<Derived*>(this);
0156 return self->service_->template try_send_n<message_type>(
0157 self->impl_, count, false, static_cast<Args2&&>(args)...);
0158 }
0159
0160 template <typename... Args2>
0161 enable_if_t<
0162 is_constructible<boost::asio::detail::completion_message<R(Args...)>,
0163 int, Args2...>::value,
0164 std::size_t
0165 > try_send_n_via_dispatch(std::size_t count, Args2&&... args)
0166 {
0167 typedef boost::asio::detail::completion_message<R(Args...)> message_type;
0168 Derived* self = static_cast<Derived*>(this);
0169 return self->service_->template try_send_n<message_type>(
0170 self->impl_, count, true, static_cast<Args2&&>(args)...);
0171 }
0172
0173 template <
0174 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code))
0175 CompletionToken BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(Executor)>
0176 auto async_send(Args... args,
0177 CompletionToken&& token
0178 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(Executor))
0179 -> decltype(
0180 async_initiate<CompletionToken, void (boost::system::error_code)>(
0181 declval<typename conditional_t<false, CompletionToken,
0182 Derived>::initiate_async_send>(), token,
0183 declval<typename conditional_t<false, CompletionToken,
0184 Derived>::payload_type>()))
0185 {
0186 typedef typename Derived::payload_type payload_type;
0187 typedef boost::asio::detail::completion_message<R(Args...)> message_type;
0188 Derived* self = static_cast<Derived*>(this);
0189 return async_initiate<CompletionToken, void (boost::system::error_code)>(
0190 typename Derived::initiate_async_send(self), token,
0191 payload_type(message_type(0, static_cast<Args&&>(args)...)));
0192 }
0193 };
0194
0195 }
0196 }
0197 }
0198 }
0199
0200 #include <boost/asio/detail/pop_options.hpp>
0201
0202 #endif