Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //
0002 // detail/win_iocp_handle_write_op.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 // Copyright (c) 2008 Rep Invariant Systems, Inc. (info@repinvariant.com)
0007 //
0008 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0009 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0010 //
0011 
0012 #ifndef BOOST_ASIO_DETAIL_WIN_IOCP_HANDLE_WRITE_OP_HPP
0013 #define BOOST_ASIO_DETAIL_WIN_IOCP_HANDLE_WRITE_OP_HPP
0014 
0015 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0016 # pragma once
0017 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0018 
0019 #include <boost/asio/detail/config.hpp>
0020 
0021 #if defined(BOOST_ASIO_HAS_IOCP)
0022 
0023 #include <boost/asio/detail/bind_handler.hpp>
0024 #include <boost/asio/detail/buffer_sequence_adapter.hpp>
0025 #include <boost/asio/detail/fenced_block.hpp>
0026 #include <boost/asio/detail/handler_alloc_helpers.hpp>
0027 #include <boost/asio/detail/handler_work.hpp>
0028 #include <boost/asio/detail/memory.hpp>
0029 #include <boost/asio/detail/operation.hpp>
0030 #include <boost/asio/error.hpp>
0031 
0032 #include <boost/asio/detail/push_options.hpp>
0033 
0034 namespace boost {
0035 namespace asio {
0036 namespace detail {
0037 
0038 template <typename ConstBufferSequence, typename Handler, typename IoExecutor>
0039 class win_iocp_handle_write_op : public operation
0040 {
0041 public:
0042   BOOST_ASIO_DEFINE_HANDLER_PTR(win_iocp_handle_write_op);
0043 
0044   win_iocp_handle_write_op(const ConstBufferSequence& buffers,
0045       Handler& handler, const IoExecutor& io_ex)
0046     : operation(&win_iocp_handle_write_op::do_complete),
0047       buffers_(buffers),
0048       handler_(static_cast<Handler&&>(handler)),
0049       work_(handler_, io_ex)
0050   {
0051   }
0052 
0053   static void do_complete(void* owner, operation* base,
0054       const boost::system::error_code& result_ec, std::size_t bytes_transferred)
0055   {
0056     boost::system::error_code ec(result_ec);
0057 
0058     // Take ownership of the operation object.
0059     BOOST_ASIO_ASSUME(base != 0);
0060     win_iocp_handle_write_op* o(static_cast<win_iocp_handle_write_op*>(base));
0061     ptr p = { boost::asio::detail::addressof(o->handler_), o, o };
0062 
0063     BOOST_ASIO_HANDLER_COMPLETION((*o));
0064 
0065     // Take ownership of the operation's outstanding work.
0066     handler_work<Handler, IoExecutor> w(
0067         static_cast<handler_work<Handler, IoExecutor>&&>(
0068           o->work_));
0069 
0070 #if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
0071     if (owner)
0072     {
0073       // Check whether buffers are still valid.
0074       buffer_sequence_adapter<boost::asio::const_buffer,
0075           ConstBufferSequence>::validate(o->buffers_);
0076     }
0077 #endif // defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
0078 
0079     BOOST_ASIO_ERROR_LOCATION(ec);
0080 
0081     // Make a copy of the handler so that the memory can be deallocated before
0082     // the upcall is made. Even if we're not about to make an upcall, a
0083     // sub-object of the handler may be the true owner of the memory associated
0084     // with the handler. Consequently, a local copy of the handler is required
0085     // to ensure that any owning sub-object remains valid until after we have
0086     // deallocated the memory here.
0087     detail::binder2<Handler, boost::system::error_code, std::size_t>
0088       handler(o->handler_, ec, bytes_transferred);
0089     p.h = boost::asio::detail::addressof(handler.handler_);
0090     p.reset();
0091 
0092     // Make the upcall if required.
0093     if (owner)
0094     {
0095       fenced_block b(fenced_block::half);
0096       BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
0097       w.complete(handler, handler.handler_);
0098       BOOST_ASIO_HANDLER_INVOCATION_END;
0099     }
0100   }
0101 
0102 private:
0103   ConstBufferSequence buffers_;
0104   Handler handler_;
0105   handler_work<Handler, IoExecutor> work_;
0106 };
0107 
0108 } // namespace detail
0109 } // namespace asio
0110 } // namespace boost
0111 
0112 #include <boost/asio/detail/pop_options.hpp>
0113 
0114 #endif // defined(BOOST_ASIO_HAS_IOCP)
0115 
0116 #endif // BOOST_ASIO_DETAIL_WIN_IOCP_HANDLE_WRITE_OP_HPP