Realistic 3D camera system
3D camera system components
win_iocp_null_buffers_op.hpp
Go to the documentation of this file.
1 //
2 // detail/win_iocp_null_buffers_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_NULL_BUFFERS_OP_HPP
12 #define ASIO_DETAIL_WIN_IOCP_NULL_BUFFERS_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 
30 #include "asio/error.hpp"
31 
33 
34 namespace asio {
35 namespace detail {
36 
37 template <typename Handler>
38 class win_iocp_null_buffers_op : public reactor_op
39 {
40 public:
41  ASIO_DEFINE_HANDLER_PTR(win_iocp_null_buffers_op);
42 
43  win_iocp_null_buffers_op(socket_ops::weak_cancel_token_type cancel_token,
44  Handler& handler)
45  : reactor_op(&win_iocp_null_buffers_op::do_perform,
46  &win_iocp_null_buffers_op::do_complete),
47  cancel_token_(cancel_token),
48  handler_(ASIO_MOVE_CAST(Handler)(handler))
49  {
50  }
51 
52  static bool do_perform(reactor_op*)
53  {
54  return true;
55  }
56 
57  static void do_complete(io_service_impl* owner, operation* base,
58  const asio::error_code& result_ec,
59  std::size_t bytes_transferred)
60  {
61  asio::error_code ec(result_ec);
62 
63  // Take ownership of the operation object.
64  win_iocp_null_buffers_op* o(static_cast<win_iocp_null_buffers_op*>(base));
65  ptr p = { asio::detail::addressof(o->handler_), o, o };
66 
68 
69  // The reactor may have stored a result in the operation object.
70  if (o->ec_)
71  ec = o->ec_;
72 
73  // Map non-portable errors to their portable counterparts.
74  if (ec.value() == ERROR_NETNAME_DELETED)
75  {
76  if (o->cancel_token_.expired())
78  else
80  }
81  else if (ec.value() == ERROR_PORT_UNREACHABLE)
82  {
84  }
85 
86  // Make a copy of the handler so that the memory can be deallocated before
87  // the upcall is made. Even if we're not about to make an upcall, a
88  // sub-object of the handler may be the true owner of the memory associated
89  // with the handler. Consequently, a local copy of the handler is required
90  // to ensure that any owning sub-object remains valid until after we have
91  // deallocated the memory here.
92  detail::binder2<Handler, asio::error_code, std::size_t>
93  handler(o->handler_, ec, bytes_transferred);
94  p.h = asio::detail::addressof(handler.handler_);
95  p.reset();
96 
97  // Make the upcall if required.
98  if (owner)
99  {
101  ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
102  asio_handler_invoke_helpers::invoke(handler, handler.handler_);
104  }
105  }
106 
107 private:
109  Handler handler_;
110 };
111 
112 } // namespace detail
113 } // namespace asio
114 
116 
117 #endif // defined(ASIO_HAS_IOCP)
118 
119 #endif // ASIO_DETAIL_WIN_IOCP_NULL_BUFFERS_OP_HPP
#define ASIO_HANDLER_INVOCATION_END
Operation cancelled.
Definition: error.hpp:161
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)
weak_ptr< void > weak_cancel_token_type
Definition: socket_ops.hpp:63
Connection refused.
Definition: error.hpp:92
#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
Connection reset by peer.
Definition: error.hpp:95