Realistic 3D camera system
3D camera system components
win_iocp_handle_read_op.hpp
Go to the documentation of this file.
1 //
2 // detail/win_iocp_handle_read_op.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 // Copyright (c) 2008 Rep Invariant Systems, Inc. (info@repinvariant.com)
7 //
8 // Distributed under the Boost Software License, Version 1.0. (See accompanying
9 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10 //
11 
12 #ifndef ASIO_DETAIL_WIN_IOCP_HANDLE_READ_OP_HPP
13 #define ASIO_DETAIL_WIN_IOCP_HANDLE_READ_OP_HPP
14 
15 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 # pragma once
17 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 
19 #include "asio/detail/config.hpp"
20 
21 #if defined(ASIO_HAS_IOCP)
22 
23 #include "asio/error.hpp"
31 
33 
34 namespace asio {
35 namespace detail {
36 
37 template <typename MutableBufferSequence, typename Handler>
38 class win_iocp_handle_read_op : public operation
39 {
40 public:
41  ASIO_DEFINE_HANDLER_PTR(win_iocp_handle_read_op);
42 
43  win_iocp_handle_read_op(
44  const MutableBufferSequence& buffers, Handler& handler)
45  : operation(&win_iocp_handle_read_op::do_complete),
46  buffers_(buffers),
47  handler_(ASIO_MOVE_CAST(Handler)(handler))
48  {
49  }
50 
51  static void do_complete(io_service_impl* owner, operation* base,
52  const asio::error_code& result_ec,
53  std::size_t bytes_transferred)
54  {
55  asio::error_code ec(result_ec);
56 
57  // Take ownership of the operation object.
58  win_iocp_handle_read_op* o(static_cast<win_iocp_handle_read_op*>(base));
59  ptr p = { asio::detail::addressof(o->handler_), o, o };
60 
62 
63 #if defined(ASIO_ENABLE_BUFFER_DEBUGGING)
64  if (owner)
65  {
66  // Check whether buffers are still valid.
67  buffer_sequence_adapter<asio::mutable_buffer,
68  MutableBufferSequence>::validate(o->buffers_);
69  }
70 #endif // defined(ASIO_ENABLE_BUFFER_DEBUGGING)
71 
72  // Map non-portable errors to their portable counterparts.
73  if (ec.value() == ERROR_HANDLE_EOF)
74  ec = asio::error::eof;
75 
76  // Make a copy of the handler so that the memory can be deallocated before
77  // the upcall is made. Even if we're not about to make an upcall, a
78  // sub-object of the handler may be the true owner of the memory associated
79  // with the handler. Consequently, a local copy of the handler is required
80  // to ensure that any owning sub-object remains valid until after we have
81  // deallocated the memory here.
82  detail::binder2<Handler, asio::error_code, std::size_t>
83  handler(o->handler_, ec, bytes_transferred);
84  p.h = asio::detail::addressof(handler.handler_);
85  p.reset();
86 
87  // Make the upcall if required.
88  if (owner)
89  {
91  ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
92  asio_handler_invoke_helpers::invoke(handler, handler.handler_);
94  }
95  }
96 
97 private:
98  MutableBufferSequence buffers_;
99  Handler handler_;
100 };
101 
102 } // namespace detail
103 } // namespace asio
104 
106 
107 #endif // defined(ASIO_HAS_IOCP)
108 
109 #endif // ASIO_DETAIL_WIN_IOCP_HANDLE_READ_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
End of file or stream.
Definition: error.hpp:217
void invoke(Function &function, Context &context)
const MutableBufferSequence & buffers
Definition: read.hpp:521
Holds a buffer that can be modified.
Definition: buffer.hpp:91
#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