Realistic 3D camera system
3D camera system components
reactive_socket_recv_op.hpp
Go to the documentation of this file.
1 //
2 // detail/reactive_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_REACTIVE_SOCKET_RECV_OP_HPP
12 #define ASIO_DETAIL_REACTIVE_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"
25 
27 
28 namespace asio {
29 namespace detail {
30 
31 template <typename MutableBufferSequence>
33 {
34 public:
36  socket_ops::state_type state, const MutableBufferSequence& buffers,
37  socket_base::message_flags flags, func_type complete_func)
39  socket_(socket),
40  state_(state),
41  buffers_(buffers),
42  flags_(flags)
43  {
44  }
45 
46  static bool do_perform(reactor_op* base)
47  {
49  static_cast<reactive_socket_recv_op_base*>(base));
50 
52  MutableBufferSequence> bufs(o->buffers_);
53 
54  return socket_ops::non_blocking_recv(o->socket_,
55  bufs.buffers(), bufs.count(), o->flags_,
56  (o->state_ & socket_ops::stream_oriented) != 0,
57  o->ec_, o->bytes_transferred_);
58  }
59 
60 private:
61  socket_type socket_;
63  MutableBufferSequence buffers_;
65 };
66 
67 template <typename MutableBufferSequence, typename Handler>
69  public reactive_socket_recv_op_base<MutableBufferSequence>
70 {
71 public:
73 
75  socket_ops::state_type state, const MutableBufferSequence& buffers,
76  socket_base::message_flags flags, Handler& handler)
77  : reactive_socket_recv_op_base<MutableBufferSequence>(socket, state,
78  buffers, flags, &reactive_socket_recv_op::do_complete),
79  handler_(ASIO_MOVE_CAST(Handler)(handler))
80  {
81  }
82 
83  static void do_complete(io_service_impl* owner, operation* base,
84  const asio::error_code& /*ec*/,
85  std::size_t /*bytes_transferred*/)
86  {
87  // Take ownership of the handler object.
88  reactive_socket_recv_op* o(static_cast<reactive_socket_recv_op*>(base));
89  ptr p = { asio::detail::addressof(o->handler_), o, o };
90 
92 
93  // Make a copy of the handler so that the memory can be deallocated before
94  // the upcall is made. Even if we're not about to make an upcall, a
95  // sub-object of the handler may be the true owner of the memory associated
96  // with the handler. Consequently, a local copy of the handler is required
97  // to ensure that any owning sub-object remains valid until after we have
98  // deallocated the memory here.
100  handler(o->handler_, o->ec_, o->bytes_transferred_);
101  p.h = asio::detail::addressof(handler.handler_);
102  p.reset();
103 
104  // Make the upcall if required.
105  if (owner)
106  {
108  ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
111  }
112  }
113 
114 private:
115  Handler handler_;
116 };
117 
118 } // namespace detail
119 } // namespace asio
120 
122 
123 #endif // ASIO_DETAIL_REACTIVE_SOCKET_RECV_OP_HPP
static void do_complete(io_service_impl *owner, operation *base, const asio::error_code &, std::size_t)
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_recv_op_base(socket_type socket, socket_ops::state_type state, const MutableBufferSequence &buffers, socket_base::message_flags flags, func_type complete_func)
reactive_socket_recv_op(socket_type socket, socket_ops::state_type state, const MutableBufferSequence &buffers, socket_base::message_flags flags, Handler &handler)
socket_type socket(int af, int type, int protocol, asio::error_code &ec)
bool non_blocking_recv(socket_type s, buf *bufs, size_t count, int flags, bool is_stream, asio::error_code &ec, size_t &bytes_transferred)
Definition: socket_ops.ipp:865
asio::basic_streambuf< Allocator > & b
Definition: read.hpp:702
class task_io_service io_service_impl
Definition: io_service.hpp:48
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)
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
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