2 // windows/overlapped_ptr.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_ASIO_WINDOWS_OVERLAPPED_PTR_HPP
12 #define BOOST_ASIO_WINDOWS_OVERLAPPED_PTR_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
20 #if defined(BOOST_ASIO_HAS_WINDOWS_OVERLAPPED_PTR) \
21 || defined(GENERATING_DOCUMENTATION)
23 #include <boost/asio/detail/noncopyable.hpp>
24 #include <boost/asio/detail/win_iocp_overlapped_ptr.hpp>
25 #include <boost/asio/io_context.hpp>
27 #include <boost/asio/detail/push_options.hpp>
33 /// Wraps a handler to create an OVERLAPPED object for use with overlapped I/O.
35 * A special-purpose smart pointer used to wrap an application handler so that
36 * it can be passed as the LPOVERLAPPED argument to overlapped I/O functions.
39 * @e Distinct @e objects: Safe.@n
40 * @e Shared @e objects: Unsafe.
46 /// Construct an empty overlapped_ptr.
52 /// Construct an overlapped_ptr to contain the specified handler.
53 template <typename ExecutionContext, typename Handler>
54 explicit overlapped_ptr(ExecutionContext& context,
55 BOOST_ASIO_MOVE_ARG(Handler) handler,
57 is_convertible<ExecutionContext&, execution_context&>::value
59 : impl_(context.get_executor(), BOOST_ASIO_MOVE_CAST(Handler)(handler))
63 /// Construct an overlapped_ptr to contain the specified handler.
64 template <typename Executor, typename Handler>
65 explicit overlapped_ptr(const Executor& ex,
66 BOOST_ASIO_MOVE_ARG(Handler) handler,
68 is_executor<Executor>::value
70 : impl_(ex, BOOST_ASIO_MOVE_CAST(Handler)(handler))
74 /// Destructor automatically frees the OVERLAPPED object unless released.
85 /// Reset to contain the specified handler, freeing any current OVERLAPPED
87 template <typename ExecutionContext, typename Handler>
88 void reset(ExecutionContext& context, BOOST_ASIO_MOVE_ARG(Handler) handler,
90 is_convertible<ExecutionContext&, execution_context&>::value
93 impl_.reset(context.get_executor(), BOOST_ASIO_MOVE_CAST(Handler)(handler));
96 /// Reset to contain the specified handler, freeing any current OVERLAPPED
98 template <typename Executor, typename Handler>
99 void reset(const Executor& ex, BOOST_ASIO_MOVE_ARG(Handler) handler,
101 is_executor<Executor>::value
104 impl_.reset(ex, BOOST_ASIO_MOVE_CAST(Handler)(handler));
107 /// Get the contained OVERLAPPED object.
113 /// Get the contained OVERLAPPED object.
114 const OVERLAPPED* get() const
119 /// Release ownership of the OVERLAPPED object.
120 OVERLAPPED* release()
122 return impl_.release();
125 /// Post completion notification for overlapped operation. Releases ownership.
126 void complete(const boost::system::error_code& ec,
127 std::size_t bytes_transferred)
129 impl_.complete(ec, bytes_transferred);
133 detail::win_iocp_overlapped_ptr impl_;
136 } // namespace windows
140 #include <boost/asio/detail/pop_options.hpp>
142 #endif // defined(BOOST_ASIO_HAS_WINDOWS_OVERLAPPED_PTR)
143 // || defined(GENERATING_DOCUMENTATION)
145 #endif // BOOST_ASIO_WINDOWS_OVERLAPPED_PTR_HPP