File indexing completed on 2025-07-11 08:05:15
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_RECEIVE_OP_HPP
0012 #define BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_RECEIVE_OP_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/detail/bind_handler.hpp>
0020 #include <boost/asio/detail/completion_handler.hpp>
0021 #include <boost/asio/detail/handler_alloc_helpers.hpp>
0022 #include <boost/asio/error.hpp>
0023 #include <boost/asio/experimental/detail/channel_operation.hpp>
0024
0025 #include <boost/asio/detail/push_options.hpp>
0026
0027 namespace boost {
0028 namespace asio {
0029 namespace experimental {
0030 namespace detail {
0031
0032 template <typename Payload>
0033 class channel_receive : public channel_operation
0034 {
0035 public:
0036 void immediate(Payload payload)
0037 {
0038 func_(this, immediate_op, &payload);
0039 }
0040
0041 void post(Payload payload)
0042 {
0043 func_(this, post_op, &payload);
0044 }
0045
0046 void dispatch(Payload payload)
0047 {
0048 func_(this, dispatch_op, &payload);
0049 }
0050
0051 protected:
0052 channel_receive(func_type func)
0053 : channel_operation(func)
0054 {
0055 }
0056 };
0057
0058 template <typename Payload, typename Handler, typename IoExecutor>
0059 class channel_receive_op : public channel_receive<Payload>
0060 {
0061 public:
0062 BOOST_ASIO_DEFINE_HANDLER_PTR(channel_receive_op);
0063
0064 template <typename... Args>
0065 channel_receive_op(Handler& handler, const IoExecutor& io_ex)
0066 : channel_receive<Payload>(&channel_receive_op::do_action),
0067 handler_(static_cast<Handler&&>(handler)),
0068 work_(handler_, io_ex)
0069 {
0070 }
0071
0072 static void do_action(channel_operation* base,
0073 channel_operation::action a, void* v)
0074 {
0075
0076 channel_receive_op* o(static_cast<channel_receive_op*>(base));
0077 ptr p = { boost::asio::detail::addressof(o->handler_), o, o };
0078
0079 BOOST_ASIO_HANDLER_COMPLETION((*o));
0080
0081
0082 channel_operation::handler_work<Handler, IoExecutor> w(
0083 static_cast<channel_operation::handler_work<Handler, IoExecutor>&&>(
0084 o->work_));
0085
0086
0087
0088
0089
0090
0091
0092 if (a != channel_operation::destroy_op)
0093 {
0094 Payload* payload = static_cast<Payload*>(v);
0095 boost::asio::detail::completion_payload_handler<Payload, Handler> handler(
0096 static_cast<Payload&&>(*payload), o->handler_);
0097 p.h = boost::asio::detail::addressof(handler.handler_);
0098 p.reset();
0099 BOOST_ASIO_HANDLER_INVOCATION_BEGIN(());
0100 if (a == channel_operation::immediate_op)
0101 w.immediate(handler, handler.handler_, 0);
0102 else if (a == channel_operation::dispatch_op)
0103 w.dispatch(handler, handler.handler_);
0104 else
0105 w.post(handler, handler.handler_);
0106 BOOST_ASIO_HANDLER_INVOCATION_END;
0107 }
0108 else
0109 {
0110 boost::asio::detail::binder0<Handler> handler(o->handler_);
0111 p.h = boost::asio::detail::addressof(handler.handler_);
0112 p.reset();
0113 }
0114 }
0115
0116 private:
0117 Handler handler_;
0118 channel_operation::handler_work<Handler, IoExecutor> work_;
0119 };
0120
0121 }
0122 }
0123 }
0124 }
0125
0126 #include <boost/asio/detail/pop_options.hpp>
0127
0128 #endif