]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/asio/include/boost/asio/detail/win_iocp_overlapped_op.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / asio / include / boost / asio / detail / win_iocp_overlapped_op.hpp
1 //
2 // detail/win_iocp_overlapped_op.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_DETAIL_WIN_IOCP_OVERLAPPED_OP_HPP
12 #define BOOST_ASIO_DETAIL_WIN_IOCP_OVERLAPPED_OP_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_IOCP)
21
22 #include <boost/asio/error.hpp>
23 #include <boost/asio/detail/addressof.hpp>
24 #include <boost/asio/detail/bind_handler.hpp>
25 #include <boost/asio/detail/fenced_block.hpp>
26 #include <boost/asio/detail/handler_alloc_helpers.hpp>
27 #include <boost/asio/detail/handler_invoke_helpers.hpp>
28 #include <boost/asio/detail/operation.hpp>
29
30 #include <boost/asio/detail/push_options.hpp>
31
32 namespace boost {
33 namespace asio {
34 namespace detail {
35
36 template <typename Handler>
37 class win_iocp_overlapped_op : public operation
38 {
39 public:
40 BOOST_ASIO_DEFINE_HANDLER_PTR(win_iocp_overlapped_op);
41
42 win_iocp_overlapped_op(Handler& handler)
43 : operation(&win_iocp_overlapped_op::do_complete),
44 handler_(BOOST_ASIO_MOVE_CAST(Handler)(handler))
45 {
46 }
47
48 static void do_complete(io_service_impl* owner, operation* base,
49 const boost::system::error_code& ec, std::size_t bytes_transferred)
50 {
51 // Take ownership of the operation object.
52 win_iocp_overlapped_op* o(static_cast<win_iocp_overlapped_op*>(base));
53 ptr p = { boost::asio::detail::addressof(o->handler_), o, o };
54
55 BOOST_ASIO_HANDLER_COMPLETION((o));
56
57 // Make a copy of the handler so that the memory can be deallocated before
58 // the upcall is made. Even if we're not about to make an upcall, a
59 // sub-object of the handler may be the true owner of the memory associated
60 // with the handler. Consequently, a local copy of the handler is required
61 // to ensure that any owning sub-object remains valid until after we have
62 // deallocated the memory here.
63 detail::binder2<Handler, boost::system::error_code, std::size_t>
64 handler(o->handler_, ec, bytes_transferred);
65 p.h = boost::asio::detail::addressof(handler.handler_);
66 p.reset();
67
68 // Make the upcall if required.
69 if (owner)
70 {
71 fenced_block b(fenced_block::half);
72 BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
73 boost_asio_handler_invoke_helpers::invoke(handler, handler.handler_);
74 BOOST_ASIO_HANDLER_INVOCATION_END;
75 }
76 }
77
78 private:
79 Handler handler_;
80 };
81
82 } // namespace detail
83 } // namespace asio
84 } // namespace boost
85
86 #include <boost/asio/detail/pop_options.hpp>
87
88 #endif // defined(BOOST_ASIO_HAS_IOCP)
89
90 #endif // BOOST_ASIO_DETAIL_WIN_IOCP_OVERLAPPED_OP_HPP