Realistic 3D camera system
3D camera system components
reactive_socket_recvmsg_op.hpp
Go to the documentation of this file.
1 //
2 // detail/reactive_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_REACTIVE_SOCKET_RECVMSG_OP_HPP
12 #define ASIO_DETAIL_REACTIVE_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"
25 #include "asio/socket_base.hpp"
26 
28 
29 namespace asio {
30 namespace detail {
31 
32 template <typename MutableBufferSequence>
34 {
35 public:
37  const MutableBufferSequence& buffers, socket_base::message_flags in_flags,
38  socket_base::message_flags& out_flags, func_type complete_func)
40  socket_(socket),
41  buffers_(buffers),
42  in_flags_(in_flags),
43  out_flags_(out_flags)
44  {
45  }
46 
47  static bool do_perform(reactor_op* base)
48  {
50  static_cast<reactive_socket_recvmsg_op_base*>(base));
51 
53  MutableBufferSequence> bufs(o->buffers_);
54 
55  return socket_ops::non_blocking_recvmsg(o->socket_,
56  bufs.buffers(), bufs.count(),
57  o->in_flags_, o->out_flags_,
58  o->ec_, o->bytes_transferred_);
59  }
60 
61 private:
62  socket_type socket_;
63  MutableBufferSequence buffers_;
65  socket_base::message_flags& out_flags_;
66 };
67 
68 template <typename MutableBufferSequence, typename Handler>
70  public reactive_socket_recvmsg_op_base<MutableBufferSequence>
71 {
72 public:
74 
76  const MutableBufferSequence& buffers, socket_base::message_flags in_flags,
77  socket_base::message_flags& out_flags, Handler& handler)
78  : reactive_socket_recvmsg_op_base<MutableBufferSequence>(socket, buffers,
79  in_flags, out_flags, &reactive_socket_recvmsg_op::do_complete),
80  handler_(ASIO_MOVE_CAST(Handler)(handler))
81  {
82  }
83 
84  static void do_complete(io_service_impl* owner, operation* base,
85  const asio::error_code& /*ec*/,
86  std::size_t /*bytes_transferred*/)
87  {
88  // Take ownership of the handler object.
90  static_cast<reactive_socket_recvmsg_op*>(base));
91  ptr p = { asio::detail::addressof(o->handler_), o, o };
92 
94 
95  // Make a copy of the handler so that the memory can be deallocated before
96  // the upcall is made. Even if we're not about to make an upcall, a
97  // sub-object of the handler may be the true owner of the memory associated
98  // with the handler. Consequently, a local copy of the handler is required
99  // to ensure that any owning sub-object remains valid until after we have
100  // deallocated the memory here.
102  handler(o->handler_, o->ec_, o->bytes_transferred_);
103  p.h = asio::detail::addressof(handler.handler_);
104  p.reset();
105 
106  // Make the upcall if required.
107  if (owner)
108  {
110  ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
113  }
114  }
115 
116 private:
117  Handler handler_;
118 };
119 
120 } // namespace detail
121 } // namespace asio
122 
124 
125 #endif // ASIO_DETAIL_REACTIVE_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
reactive_socket_recvmsg_op_base(socket_type socket, const MutableBufferSequence &buffers, socket_base::message_flags in_flags, socket_base::message_flags &out_flags, func_type complete_func)
socket_type socket(int af, int type, int protocol, asio::error_code &ec)
asio::basic_streambuf< Allocator > & b
Definition: read.hpp:702
class task_io_service io_service_impl
Definition: io_service.hpp:48
static void do_complete(io_service_impl *owner, operation *base, const asio::error_code &, std::size_t)
void invoke(Function &function, Context &context)
const MutableBufferSequence & buffers
Definition: read.hpp:521
Holds a buffer that can be modified.
Definition: buffer.hpp:91
bool non_blocking_recvmsg(socket_type s, buf *bufs, size_t count, int in_flags, int &out_flags, asio::error_code &ec, size_t &bytes_transferred)
#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
asio::error_code ec_
Definition: reactor_op.hpp:31
std::size_t bytes_transferred_
Definition: reactor_op.hpp:34
#define ASIO_DEFINE_HANDLER_PTR(op)
#define ASIO_HANDLER_COMPLETION(args)
#define ASIO_MOVE_CAST(type)
Definition: config.hpp:138
reactive_socket_recvmsg_op(socket_type socket, const MutableBufferSequence &buffers, socket_base::message_flags in_flags, socket_base::message_flags &out_flags, Handler &handler)