Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:03

0001 //
0002 // windows/overlapped_ptr.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_WINDOWS_OVERLAPPED_PTR_HPP
0012 #define BOOST_ASIO_WINDOWS_OVERLAPPED_PTR_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 
0020 #if defined(BOOST_ASIO_HAS_WINDOWS_OVERLAPPED_PTR) \
0021   || defined(GENERATING_DOCUMENTATION)
0022 
0023 #include <boost/asio/detail/noncopyable.hpp>
0024 #include <boost/asio/detail/win_iocp_overlapped_ptr.hpp>
0025 #include <boost/asio/io_context.hpp>
0026 
0027 #include <boost/asio/detail/push_options.hpp>
0028 
0029 namespace boost {
0030 namespace asio {
0031 namespace windows {
0032 
0033 /// Wraps a handler to create an OVERLAPPED object for use with overlapped I/O.
0034 /**
0035  * A special-purpose smart pointer used to wrap an application handler so that
0036  * it can be passed as the LPOVERLAPPED argument to overlapped I/O functions.
0037  *
0038  * @par Thread Safety
0039  * @e Distinct @e objects: Safe.@n
0040  * @e Shared @e objects: Unsafe.
0041  */
0042 class overlapped_ptr
0043   : private noncopyable
0044 {
0045 public:
0046   /// Construct an empty overlapped_ptr.
0047   overlapped_ptr()
0048     : impl_()
0049   {
0050   }
0051 
0052   /// Construct an overlapped_ptr to contain the specified handler.
0053   template <typename ExecutionContext, typename Handler>
0054   explicit overlapped_ptr(ExecutionContext& context,
0055       Handler&& handler,
0056       constraint_t<
0057         is_convertible<ExecutionContext&, execution_context&>::value
0058       > = 0)
0059     : impl_(context.get_executor(), static_cast<Handler&&>(handler))
0060   {
0061   }
0062 
0063   /// Construct an overlapped_ptr to contain the specified handler.
0064   template <typename Executor, typename Handler>
0065   explicit overlapped_ptr(const Executor& ex,
0066       Handler&& handler,
0067       constraint_t<
0068         execution::is_executor<Executor>::value
0069           || is_executor<Executor>::value
0070       > = 0)
0071     : impl_(ex, static_cast<Handler&&>(handler))
0072   {
0073   }
0074 
0075   /// Destructor automatically frees the OVERLAPPED object unless released.
0076   ~overlapped_ptr()
0077   {
0078   }
0079 
0080   /// Reset to empty.
0081   void reset()
0082   {
0083     impl_.reset();
0084   }
0085 
0086   /// Reset to contain the specified handler, freeing any current OVERLAPPED
0087   /// object.
0088   template <typename ExecutionContext, typename Handler>
0089   void reset(ExecutionContext& context, Handler&& handler,
0090       constraint_t<
0091         is_convertible<ExecutionContext&, execution_context&>::value
0092       > = 0)
0093   {
0094     impl_.reset(context.get_executor(), static_cast<Handler&&>(handler));
0095   }
0096 
0097   /// Reset to contain the specified handler, freeing any current OVERLAPPED
0098   /// object.
0099   template <typename Executor, typename Handler>
0100   void reset(const Executor& ex, Handler&& handler,
0101       constraint_t<
0102         execution::is_executor<Executor>::value
0103           || is_executor<Executor>::value
0104       > = 0)
0105   {
0106     impl_.reset(ex, static_cast<Handler&&>(handler));
0107   }
0108 
0109   /// Get the contained OVERLAPPED object.
0110   OVERLAPPED* get()
0111   {
0112     return impl_.get();
0113   }
0114 
0115   /// Get the contained OVERLAPPED object.
0116   const OVERLAPPED* get() const
0117   {
0118     return impl_.get();
0119   }
0120 
0121   /// Release ownership of the OVERLAPPED object.
0122   OVERLAPPED* release()
0123   {
0124     return impl_.release();
0125   }
0126 
0127   /// Post completion notification for overlapped operation. Releases ownership.
0128   void complete(const boost::system::error_code& ec,
0129       std::size_t bytes_transferred)
0130   {
0131     impl_.complete(ec, bytes_transferred);
0132   }
0133 
0134 private:
0135   detail::win_iocp_overlapped_ptr impl_;
0136 };
0137 
0138 } // namespace windows
0139 } // namespace asio
0140 } // namespace boost
0141 
0142 #include <boost/asio/detail/pop_options.hpp>
0143 
0144 #endif // defined(BOOST_ASIO_HAS_WINDOWS_OVERLAPPED_PTR)
0145        //   || defined(GENERATING_DOCUMENTATION)
0146 
0147 #endif // BOOST_ASIO_WINDOWS_OVERLAPPED_PTR_HPP