Realistic 3D camera system
3D camera system components
win_iocp_socket_recvmsg_op.hpp
Go to the documentation of this file.
1 //
2 // detail/win_iocp_socket_recvmsg_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_RECVMSG_OP_HPP
12 #define ASIO_DETAIL_WIN_IOCP_SOCKET_RECVMSG_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 #include "asio/socket_base.hpp"
32 
34 
35 namespace asio {
36 namespace detail {
37 
38 template <typename MutableBufferSequence, typename Handler>
39 class win_iocp_socket_recvmsg_op : public operation
40 {
41 public:
42  ASIO_DEFINE_HANDLER_PTR(win_iocp_socket_recvmsg_op);
43 
44  win_iocp_socket_recvmsg_op(
46  const MutableBufferSequence& buffers,
47  socket_base::message_flags& out_flags, Handler& handler)
48  : operation(&win_iocp_socket_recvmsg_op::do_complete),
49  cancel_token_(cancel_token),
50  buffers_(buffers),
51  out_flags_(out_flags),
52  handler_(ASIO_MOVE_CAST(Handler)(handler))
53  {
54  }
55 
56  static void do_complete(io_service_impl* owner, operation* base,
57  const asio::error_code& result_ec,
58  std::size_t bytes_transferred)
59  {
60  asio::error_code ec(result_ec);
61 
62  // Take ownership of the operation object.
63  win_iocp_socket_recvmsg_op* o(
64  static_cast<win_iocp_socket_recvmsg_op*>(base));
65  ptr p = { asio::detail::addressof(o->handler_), o, o };
66 
68 
69 #if defined(ASIO_ENABLE_BUFFER_DEBUGGING)
70  // Check whether buffers are still valid.
71  if (owner)
72  {
73  buffer_sequence_adapter<asio::mutable_buffer,
74  MutableBufferSequence>::validate(o->buffers_);
75  }
76 #endif // defined(ASIO_ENABLE_BUFFER_DEBUGGING)
77 
78  socket_ops::complete_iocp_recvmsg(o->cancel_token_, ec);
79  o->out_flags_ = 0;
80 
81  // Make a copy of the handler so that the memory can be deallocated before
82  // the upcall is made. Even if we're not about to make an upcall, a
83  // sub-object of the handler may be the true owner of the memory associated
84  // with the handler. Consequently, a local copy of the handler is required
85  // to ensure that any owning sub-object remains valid until after we have
86  // deallocated the memory here.
87  detail::binder2<Handler, asio::error_code, std::size_t>
88  handler(o->handler_, ec, bytes_transferred);
89  p.h = asio::detail::addressof(handler.handler_);
90  p.reset();
91 
92  // Make the upcall if required.
93  if (owner)
94  {
96  ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
97  asio_handler_invoke_helpers::invoke(handler, handler.handler_);
99  }
100  }
101 
102 private:
104  MutableBufferSequence buffers_;
105  socket_base::message_flags& out_flags_;
106  Handler handler_;
107 };
108 
109 } // namespace detail
110 } // namespace asio
111 
113 
114 #endif // defined(ASIO_HAS_IOCP)
115 
116 #endif // ASIO_DETAIL_WIN_IOCP_SOCKET_RECVMSG_OP_HPP
int message_flags
Bitmask type for flags that can be passed to send and receive operations.
Definition: socket_base.hpp:53
#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)
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