Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:40

0001 //
0002 // detail/io_uring_null_buffers_op.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 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_DETAIL_IO_URING_NULL_BUFFERS_OP_HPP
0012 #define BOOST_ASIO_DETAIL_IO_URING_NULL_BUFFERS_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/fenced_block.hpp>
0021 #include <boost/asio/detail/handler_alloc_helpers.hpp>
0022 #include <boost/asio/detail/handler_work.hpp>
0023 #include <boost/asio/detail/io_uring_operation.hpp>
0024 #include <boost/asio/detail/memory.hpp>
0025 
0026 #include <boost/asio/detail/push_options.hpp>
0027 
0028 namespace boost {
0029 namespace asio {
0030 namespace detail {
0031 
0032 template <typename Handler, typename IoExecutor>
0033 class io_uring_null_buffers_op : public io_uring_operation
0034 {
0035 public:
0036   BOOST_ASIO_DEFINE_HANDLER_PTR(io_uring_null_buffers_op);
0037 
0038   io_uring_null_buffers_op(const boost::system::error_code& success_ec,
0039       int descriptor, int poll_flags, Handler& handler, const IoExecutor& io_ex)
0040     : io_uring_operation(success_ec,
0041         &io_uring_null_buffers_op::do_prepare,
0042         &io_uring_null_buffers_op::do_perform,
0043         &io_uring_null_buffers_op::do_complete),
0044       handler_(static_cast<Handler&&>(handler)),
0045       work_(handler_, io_ex),
0046       descriptor_(descriptor),
0047       poll_flags_(poll_flags)
0048   {
0049   }
0050 
0051   static void do_prepare(io_uring_operation* base, ::io_uring_sqe* sqe)
0052   {
0053     BOOST_ASIO_ASSUME(base != 0);
0054     io_uring_null_buffers_op* o(static_cast<io_uring_null_buffers_op*>(base));
0055 
0056     ::io_uring_prep_poll_add(sqe, o->descriptor_, o->poll_flags_);
0057   }
0058 
0059   static bool do_perform(io_uring_operation*, bool after_completion)
0060   {
0061     return after_completion;
0062   }
0063 
0064   static void do_complete(void* owner, operation* base,
0065       const boost::system::error_code& /*ec*/,
0066       std::size_t /*bytes_transferred*/)
0067   {
0068     // Take ownership of the handler object.
0069     BOOST_ASIO_ASSUME(base != 0);
0070     io_uring_null_buffers_op* o(static_cast<io_uring_null_buffers_op*>(base));
0071     ptr p = { boost::asio::detail::addressof(o->handler_), o, o };
0072 
0073     BOOST_ASIO_HANDLER_COMPLETION((*o));
0074 
0075     // Take ownership of the operation's outstanding work.
0076     handler_work<Handler, IoExecutor> w(
0077         static_cast<handler_work<Handler, IoExecutor>&&>(
0078           o->work_));
0079 
0080     BOOST_ASIO_ERROR_LOCATION(o->ec_);
0081 
0082     // Make a copy of the handler so that the memory can be deallocated before
0083     // the upcall is made. Even if we're not about to make an upcall, a
0084     // sub-object of the handler may be the true owner of the memory associated
0085     // with the handler. Consequently, a local copy of the handler is required
0086     // to ensure that any owning sub-object remains valid until after we have
0087     // deallocated the memory here.
0088     detail::binder2<Handler, boost::system::error_code, std::size_t>
0089       handler(o->handler_, o->ec_, o->bytes_transferred_);
0090     p.h = boost::asio::detail::addressof(handler.handler_);
0091     p.reset();
0092 
0093     // Make the upcall if required.
0094     if (owner)
0095     {
0096       fenced_block b(fenced_block::half);
0097       BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
0098       w.complete(handler, handler.handler_);
0099       BOOST_ASIO_HANDLER_INVOCATION_END;
0100     }
0101   }
0102 
0103 private:
0104   Handler handler_;
0105   handler_work<Handler, IoExecutor> work_;
0106   int descriptor_;
0107   int poll_flags_;
0108 };
0109 
0110 } // namespace detail
0111 } // namespace asio
0112 } // namespace boost
0113 
0114 #include <boost/asio/detail/pop_options.hpp>
0115 
0116 #endif // BOOST_ASIO_DETAIL_IO_URING_NULL_BUFFERS_OP_HPP