Realistic 3D camera system
3D camera system components
win_iocp_overlapped_op.hpp
Go to the documentation of this file.
1 //
2 // detail/win_iocp_overlapped_op.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 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 ASIO_DETAIL_WIN_IOCP_OVERLAPPED_OP_HPP
12 #define 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 "asio/detail/config.hpp"
19 
20 #if defined(ASIO_HAS_IOCP)
21 
22 #include "asio/error.hpp"
29 
31 
32 namespace asio {
33 namespace detail {
34 
35 template <typename Handler>
36 class win_iocp_overlapped_op : public operation
37 {
38 public:
39  ASIO_DEFINE_HANDLER_PTR(win_iocp_overlapped_op);
40 
41  win_iocp_overlapped_op(Handler& handler)
42  : operation(&win_iocp_overlapped_op::do_complete),
43  handler_(ASIO_MOVE_CAST(Handler)(handler))
44  {
45  }
46 
47  static void do_complete(io_service_impl* owner, operation* base,
48  const asio::error_code& ec, std::size_t bytes_transferred)
49  {
50  // Take ownership of the operation object.
51  win_iocp_overlapped_op* o(static_cast<win_iocp_overlapped_op*>(base));
52  ptr p = { asio::detail::addressof(o->handler_), o, o };
53 
55 
56  // Make a copy of the handler so that the memory can be deallocated before
57  // the upcall is made. Even if we're not about to make an upcall, a
58  // sub-object of the handler may be the true owner of the memory associated
59  // with the handler. Consequently, a local copy of the handler is required
60  // to ensure that any owning sub-object remains valid until after we have
61  // deallocated the memory here.
62  detail::binder2<Handler, asio::error_code, std::size_t>
63  handler(o->handler_, ec, bytes_transferred);
64  p.h = asio::detail::addressof(handler.handler_);
65  p.reset();
66 
67  // Make the upcall if required.
68  if (owner)
69  {
71  ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
72  asio_handler_invoke_helpers::invoke(handler, handler.handler_);
74  }
75  }
76 
77 private:
78  Handler handler_;
79 };
80 
81 } // namespace detail
82 } // namespace asio
83 
85 
86 #endif // defined(ASIO_HAS_IOCP)
87 
88 #endif // ASIO_DETAIL_WIN_IOCP_OVERLAPPED_OP_HPP
#define ASIO_HANDLER_INVOCATION_END
asio::basic_streambuf< Allocator > & b
Definition: read.hpp:702
null_fenced_block fenced_block
class task_io_service io_service_impl
Definition: io_service.hpp:48
void invoke(Function &function, Context &context)
#define ASIO_HANDLER_INVOCATION_BEGIN(args)
Class to represent an error code value.
Definition: error_code.hpp:80
task_io_service_operation operation
Definition: operation.hpp:32
#define ASIO_DEFINE_HANDLER_PTR(op)
#define ASIO_HANDLER_COMPLETION(args)
#define ASIO_MOVE_CAST(type)
Definition: config.hpp:138