Realistic 3D camera system
3D camera system components
win_iocp_socket_recv_op.hpp
Go to the documentation of this file.
1 //
2 // detail/win_iocp_socket_recv_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_SOCKET_RECV_OP_HPP
12 #define ASIO_DETAIL_WIN_IOCP_SOCKET_RECV_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 MutableBufferSequence, typename Handler>
38 class win_iocp_socket_recv_op : public operation
39 {
40 public:
41  ASIO_DEFINE_HANDLER_PTR(win_iocp_socket_recv_op);
42 
43  win_iocp_socket_recv_op(socket_ops::state_type state,
45  const MutableBufferSequence& buffers, Handler& handler)
46  : operation(&win_iocp_socket_recv_op::do_complete),
47  state_(state),
48  cancel_token_(cancel_token),
49  buffers_(buffers),
50  handler_(ASIO_MOVE_CAST(Handler)(handler))
51  {
52  }
53 
54  static void do_complete(io_service_impl* owner, operation* base,
55  const asio::error_code& result_ec,
56  std::size_t bytes_transferred)
57  {
58  asio::error_code ec(result_ec);
59 
60  // Take ownership of the operation object.
61  win_iocp_socket_recv_op* o(static_cast<win_iocp_socket_recv_op*>(base));
62  ptr p = { asio::detail::addressof(o->handler_), o, o };
63 
65 
66 #if defined(ASIO_ENABLE_BUFFER_DEBUGGING)
67  // Check whether buffers are still valid.
68  if (owner)
69  {
70  buffer_sequence_adapter<asio::mutable_buffer,
71  MutableBufferSequence>::validate(o->buffers_);
72  }
73 #endif // defined(ASIO_ENABLE_BUFFER_DEBUGGING)
74 
75  socket_ops::complete_iocp_recv(o->state_, o->cancel_token_,
76  buffer_sequence_adapter<asio::mutable_buffer,
77  MutableBufferSequence>::all_empty(o->buffers_),
78  ec, bytes_transferred);
79 
80  // Make a copy of the handler so that the memory can be deallocated before
81  // the upcall is made. Even if we're not about to make an upcall, a
82  // sub-object of the handler may be the true owner of the memory associated
83  // with the handler. Consequently, a local copy of the handler is required
84  // to ensure that any owning sub-object remains valid until after we have
85  // deallocated the memory here.
86  detail::binder2<Handler, asio::error_code, std::size_t>
87  handler(o->handler_, ec, bytes_transferred);
88  p.h = asio::detail::addressof(handler.handler_);
89  p.reset();
90 
91  // Make the upcall if required.
92  if (owner)
93  {
95  ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
96  asio_handler_invoke_helpers::invoke(handler, handler.handler_);
98  }
99  }
100 
101 private:
102  socket_ops::state_type state_;
104  MutableBufferSequence buffers_;
105  Handler handler_;
106 };
107 
108 } // namespace detail
109 } // namespace asio
110 
112 
113 #endif // defined(ASIO_HAS_IOCP)
114 
115 #endif // ASIO_DETAIL_WIN_IOCP_SOCKET_RECV_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)
weak_ptr< void > weak_cancel_token_type
Definition: socket_ops.hpp:63
const MutableBufferSequence & buffers
Definition: read.hpp:521
Holds a buffer that can be modified.
Definition: buffer.hpp:91
#define ASIO_HANDLER_INVOCATION_BEGIN(args)
unsigned char state_type
Definition: socket_ops.hpp:59
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