]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/asio/include/boost/asio/windows/overlapped_ptr.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / asio / include / boost / asio / windows / overlapped_ptr.hpp
1 //
2 // windows/overlapped_ptr.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
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)
9 //
10
11 #ifndef BOOST_ASIO_WINDOWS_OVERLAPPED_PTR_HPP
12 #define BOOST_ASIO_WINDOWS_OVERLAPPED_PTR_HPP
13
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
18 #include <boost/asio/detail/config.hpp>
19
20 #if defined(BOOST_ASIO_HAS_WINDOWS_OVERLAPPED_PTR) \
21 || defined(GENERATING_DOCUMENTATION)
22
23 #include <boost/asio/detail/noncopyable.hpp>
24 #include <boost/asio/detail/win_iocp_overlapped_ptr.hpp>
25 #include <boost/asio/io_service.hpp>
26
27 #include <boost/asio/detail/push_options.hpp>
28
29 namespace boost {
30 namespace asio {
31 namespace windows {
32
33 /// Wraps a handler to create an OVERLAPPED object for use with overlapped I/O.
34 /**
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.
37 *
38 * @par Thread Safety
39 * @e Distinct @e objects: Safe.@n
40 * @e Shared @e objects: Unsafe.
41 */
42 class overlapped_ptr
43 : private noncopyable
44 {
45 public:
46 /// Construct an empty overlapped_ptr.
47 overlapped_ptr()
48 : impl_()
49 {
50 }
51
52 /// Construct an overlapped_ptr to contain the specified handler.
53 template <typename Handler>
54 explicit overlapped_ptr(boost::asio::io_service& io_service,
55 BOOST_ASIO_MOVE_ARG(Handler) handler)
56 : impl_(io_service, BOOST_ASIO_MOVE_CAST(Handler)(handler))
57 {
58 }
59
60 /// Destructor automatically frees the OVERLAPPED object unless released.
61 ~overlapped_ptr()
62 {
63 }
64
65 /// Reset to empty.
66 void reset()
67 {
68 impl_.reset();
69 }
70
71 /// Reset to contain the specified handler, freeing any current OVERLAPPED
72 /// object.
73 template <typename Handler>
74 void reset(boost::asio::io_service& io_service,
75 BOOST_ASIO_MOVE_ARG(Handler) handler)
76 {
77 impl_.reset(io_service, BOOST_ASIO_MOVE_CAST(Handler)(handler));
78 }
79
80 /// Get the contained OVERLAPPED object.
81 OVERLAPPED* get()
82 {
83 return impl_.get();
84 }
85
86 /// Get the contained OVERLAPPED object.
87 const OVERLAPPED* get() const
88 {
89 return impl_.get();
90 }
91
92 /// Release ownership of the OVERLAPPED object.
93 OVERLAPPED* release()
94 {
95 return impl_.release();
96 }
97
98 /// Post completion notification for overlapped operation. Releases ownership.
99 void complete(const boost::system::error_code& ec,
100 std::size_t bytes_transferred)
101 {
102 impl_.complete(ec, bytes_transferred);
103 }
104
105 private:
106 detail::win_iocp_overlapped_ptr impl_;
107 };
108
109 } // namespace windows
110 } // namespace asio
111 } // namespace boost
112
113 #include <boost/asio/detail/pop_options.hpp>
114
115 #endif // defined(BOOST_ASIO_HAS_WINDOWS_OVERLAPPED_PTR)
116 // || defined(GENERATING_DOCUMENTATION)
117
118 #endif // BOOST_ASIO_WINDOWS_OVERLAPPED_PTR_HPP