File indexing completed on 2025-06-30 08:08:02
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_DETAIL_WRAPPED_HANDLER_HPP
0012 #define BOOST_ASIO_DETAIL_WRAPPED_HANDLER_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/bind_handler.hpp>
0019 #include <boost/asio/detail/handler_cont_helpers.hpp>
0020
0021 #include <boost/asio/detail/push_options.hpp>
0022
0023 namespace boost {
0024 namespace asio {
0025 namespace detail {
0026
0027 struct is_continuation_delegated
0028 {
0029 template <typename Dispatcher, typename Handler>
0030 bool operator()(Dispatcher&, Handler& handler) const
0031 {
0032 return boost_asio_handler_cont_helpers::is_continuation(handler);
0033 }
0034 };
0035
0036 struct is_continuation_if_running
0037 {
0038 template <typename Dispatcher, typename Handler>
0039 bool operator()(Dispatcher& dispatcher, Handler&) const
0040 {
0041 return dispatcher.running_in_this_thread();
0042 }
0043 };
0044
0045 template <typename Dispatcher, typename = void>
0046 struct wrapped_executor
0047 {
0048 typedef Dispatcher executor_type;
0049
0050 static const Dispatcher& get(const Dispatcher& dispatcher) noexcept
0051 {
0052 return dispatcher;
0053 }
0054 };
0055
0056 template <typename Dispatcher>
0057 struct wrapped_executor<Dispatcher,
0058 void_type<typename Dispatcher::executor_type>>
0059 {
0060 typedef typename Dispatcher::executor_type executor_type;
0061
0062 static executor_type get(const Dispatcher& dispatcher) noexcept
0063 {
0064 return dispatcher.get_executor();
0065 }
0066 };
0067
0068 template <typename Dispatcher, typename Handler,
0069 typename IsContinuation = is_continuation_delegated>
0070 class wrapped_handler
0071 {
0072 public:
0073 typedef void result_type;
0074 typedef typename wrapped_executor<Dispatcher>::executor_type executor_type;
0075
0076 wrapped_handler(Dispatcher dispatcher, Handler& handler)
0077 : dispatcher_(dispatcher),
0078 handler_(static_cast<Handler&&>(handler))
0079 {
0080 }
0081
0082 wrapped_handler(const wrapped_handler& other)
0083 : dispatcher_(other.dispatcher_),
0084 handler_(other.handler_)
0085 {
0086 }
0087
0088 wrapped_handler(wrapped_handler&& other)
0089 : dispatcher_(other.dispatcher_),
0090 handler_(static_cast<Handler&&>(other.handler_))
0091 {
0092 }
0093
0094 executor_type get_executor() const noexcept
0095 {
0096 return wrapped_executor<Dispatcher>::get(dispatcher_);
0097 }
0098
0099 void operator()()
0100 {
0101 dispatcher_.dispatch(static_cast<Handler&&>(handler_));
0102 }
0103
0104 void operator()() const
0105 {
0106 dispatcher_.dispatch(handler_);
0107 }
0108
0109 template <typename Arg1>
0110 void operator()(const Arg1& arg1)
0111 {
0112 dispatcher_.dispatch(detail::bind_handler(handler_, arg1));
0113 }
0114
0115 template <typename Arg1>
0116 void operator()(const Arg1& arg1) const
0117 {
0118 dispatcher_.dispatch(detail::bind_handler(handler_, arg1));
0119 }
0120
0121 template <typename Arg1, typename Arg2>
0122 void operator()(const Arg1& arg1, const Arg2& arg2)
0123 {
0124 dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2));
0125 }
0126
0127 template <typename Arg1, typename Arg2>
0128 void operator()(const Arg1& arg1, const Arg2& arg2) const
0129 {
0130 dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2));
0131 }
0132
0133 template <typename Arg1, typename Arg2, typename Arg3>
0134 void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3)
0135 {
0136 dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2, arg3));
0137 }
0138
0139 template <typename Arg1, typename Arg2, typename Arg3>
0140 void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3) const
0141 {
0142 dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2, arg3));
0143 }
0144
0145 template <typename Arg1, typename Arg2, typename Arg3, typename Arg4>
0146 void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
0147 const Arg4& arg4)
0148 {
0149 dispatcher_.dispatch(
0150 detail::bind_handler(handler_, arg1, arg2, arg3, arg4));
0151 }
0152
0153 template <typename Arg1, typename Arg2, typename Arg3, typename Arg4>
0154 void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
0155 const Arg4& arg4) const
0156 {
0157 dispatcher_.dispatch(
0158 detail::bind_handler(handler_, arg1, arg2, arg3, arg4));
0159 }
0160
0161 template <typename Arg1, typename Arg2, typename Arg3, typename Arg4,
0162 typename Arg5>
0163 void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
0164 const Arg4& arg4, const Arg5& arg5)
0165 {
0166 dispatcher_.dispatch(
0167 detail::bind_handler(handler_, arg1, arg2, arg3, arg4, arg5));
0168 }
0169
0170 template <typename Arg1, typename Arg2, typename Arg3, typename Arg4,
0171 typename Arg5>
0172 void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
0173 const Arg4& arg4, const Arg5& arg5) const
0174 {
0175 dispatcher_.dispatch(
0176 detail::bind_handler(handler_, arg1, arg2, arg3, arg4, arg5));
0177 }
0178
0179
0180 Dispatcher dispatcher_;
0181 Handler handler_;
0182 };
0183
0184 template <typename Dispatcher, typename Handler, typename IsContinuation>
0185 inline bool asio_handler_is_continuation(
0186 wrapped_handler<Dispatcher, Handler, IsContinuation>* this_handler)
0187 {
0188 return IsContinuation()(this_handler->dispatcher_, this_handler->handler_);
0189 }
0190
0191 }
0192 }
0193 }
0194
0195 #include <boost/asio/detail/pop_options.hpp>
0196
0197 #endif