Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/asio/experimental/detail/channel_send_op.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //
0002 // experimental/detail/channel_send_op.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_SEND_OP_HPP
0012 #define BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_SEND_OP_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 #include <boost/asio/detail/bind_handler.hpp>
0020 #include <boost/asio/detail/handler_alloc_helpers.hpp>
0021 #include <boost/asio/error.hpp>
0022 #include <boost/asio/experimental/channel_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_send : public channel_operation
0034 {
0035 public:
0036   Payload get_payload()
0037   {
0038     return static_cast<Payload&&>(payload_);
0039   }
0040 
0041   void immediate()
0042   {
0043     func_(this, immediate_op, 0);
0044   }
0045 
0046   void post()
0047   {
0048     func_(this, post_op, 0);
0049   }
0050 
0051   void cancel()
0052   {
0053     func_(this, cancel_op, 0);
0054   }
0055 
0056   void close()
0057   {
0058     func_(this, close_op, 0);
0059   }
0060 
0061 protected:
0062   channel_send(func_type func, Payload&& payload)
0063     : channel_operation(func),
0064       payload_(static_cast<Payload&&>(payload))
0065   {
0066   }
0067 
0068 private:
0069   Payload payload_;
0070 };
0071 
0072 template <typename Payload, typename Handler, typename IoExecutor>
0073 class channel_send_op : public channel_send<Payload>
0074 {
0075 public:
0076   BOOST_ASIO_DEFINE_HANDLER_PTR(channel_send_op);
0077 
0078   channel_send_op(Payload&& payload,
0079       Handler& handler, const IoExecutor& io_ex)
0080     : channel_send<Payload>(&channel_send_op::do_action,
0081         static_cast<Payload&&>(payload)),
0082       handler_(static_cast<Handler&&>(handler)),
0083       work_(handler_, io_ex)
0084   {
0085   }
0086 
0087   static void do_action(channel_operation* base,
0088       channel_operation::action a, void*)
0089   {
0090     // Take ownership of the operation object.
0091     channel_send_op* o(static_cast<channel_send_op*>(base));
0092     ptr p = { boost::asio::detail::addressof(o->handler_), o, o };
0093 
0094     BOOST_ASIO_HANDLER_COMPLETION((*o));
0095 
0096     // Take ownership of the operation's outstanding work.
0097     channel_operation::handler_work<Handler, IoExecutor> w(
0098         static_cast<channel_operation::handler_work<Handler, IoExecutor>&&>(
0099           o->work_));
0100 
0101     boost::system::error_code ec;
0102     switch (a)
0103     {
0104     case channel_operation::cancel_op:
0105       ec = error::channel_cancelled;
0106       break;
0107     case channel_operation::close_op:
0108       ec = error::channel_closed;
0109       break;
0110     default:
0111       break;
0112     }
0113 
0114     // Make a copy of the handler so that the memory can be deallocated before
0115     // the handler is posted. Even if we're not about to post the handler, a
0116     // sub-object of the handler may be the true owner of the memory associated
0117     // with the handler. Consequently, a local copy of the handler is required
0118     // to ensure that any owning sub-object remains valid until after we have
0119     // deallocated the memory here.
0120     boost::asio::detail::binder1<Handler, boost::system::error_code>
0121       handler(o->handler_, ec);
0122     p.h = boost::asio::detail::addressof(handler.handler_);
0123     p.reset();
0124 
0125     // Post the completion if required.
0126     if (a != channel_operation::destroy_op)
0127     {
0128       BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_));
0129       if (a == channel_operation::immediate_op)
0130         w.immediate(handler, handler.handler_, 0);
0131       else
0132         w.post(handler, handler.handler_);
0133       BOOST_ASIO_HANDLER_INVOCATION_END;
0134     }
0135   }
0136 
0137 private:
0138   Handler handler_;
0139   channel_operation::handler_work<Handler, IoExecutor> work_;
0140 };
0141 
0142 } // namespace detail
0143 } // namespace experimental
0144 } // namespace asio
0145 } // namespace boost
0146 
0147 #include <boost/asio/detail/pop_options.hpp>
0148 
0149 #endif // BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_SEND_OP_HPP