Realistic 3D camera system
3D camera system components
reactive_socket_send_op.hpp
Go to the documentation of this file.
1 //
2 // detail/reactive_socket_send_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_SEND_OP_HPP
12 #define ASIO_DETAIL_REACTIVE_SOCKET_SEND_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 ConstBufferSequence>
33 {
34 public:
36  const ConstBufferSequence& buffers,
37  socket_base::message_flags flags, func_type complete_func)
39  socket_(socket),
40  buffers_(buffers),
41  flags_(flags)
42  {
43  }
44 
45  static bool do_perform(reactor_op* base)
46  {
48  static_cast<reactive_socket_send_op_base*>(base));
49 
51  ConstBufferSequence> bufs(o->buffers_);
52 
53  return socket_ops::non_blocking_send(o->socket_,
54  bufs.buffers(), bufs.count(), o->flags_,
55  o->ec_, o->bytes_transferred_);
56  }
57 
58 private:
59  socket_type socket_;
60  ConstBufferSequence buffers_;
62 };
63 
64 template <typename ConstBufferSequence, typename Handler>
66  public reactive_socket_send_op_base<ConstBufferSequence>
67 {
68 public:
70 
72  const ConstBufferSequence& buffers,
73  socket_base::message_flags flags, Handler& handler)
74  : reactive_socket_send_op_base<ConstBufferSequence>(socket,
75  buffers, flags, &reactive_socket_send_op::do_complete),
76  handler_(ASIO_MOVE_CAST(Handler)(handler))
77  {
78  }
79 
80  static void do_complete(io_service_impl* owner, operation* base,
81  const asio::error_code& /*ec*/,
82  std::size_t /*bytes_transferred*/)
83  {
84  // Take ownership of the handler object.
85  reactive_socket_send_op* o(static_cast<reactive_socket_send_op*>(base));
86  ptr p = { asio::detail::addressof(o->handler_), o, o };
87 
89 
90  // Make a copy of the handler so that the memory can be deallocated before
91  // the upcall is made. Even if we're not about to make an upcall, a
92  // sub-object of the handler may be the true owner of the memory associated
93  // with the handler. Consequently, a local copy of the handler is required
94  // to ensure that any owning sub-object remains valid until after we have
95  // deallocated the memory here.
97  handler(o->handler_, o->ec_, o->bytes_transferred_);
98  p.h = asio::detail::addressof(handler.handler_);
99  p.reset();
100 
101  // Make the upcall if required.
102  if (owner)
103  {
105  ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
108  }
109  }
110 
111 private:
112  Handler handler_;
113 };
114 
115 } // namespace detail
116 } // namespace asio
117 
119 
120 #endif // ASIO_DETAIL_REACTIVE_SOCKET_SEND_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
Holds a buffer that cannot be modified.
Definition: buffer.hpp:211
socket_type socket(int af, int type, int protocol, asio::error_code &ec)
bool non_blocking_send(socket_type s, const buf *bufs, size_t count, int flags, asio::error_code &ec, size_t &bytes_transferred)
static void do_complete(io_service_impl *owner, operation *base, const asio::error_code &, std::size_t)
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
#define ASIO_HANDLER_INVOCATION_BEGIN(args)
Class to represent an error code value.
Definition: error_code.hpp:80
reactive_socket_send_op_base(socket_type socket, const ConstBufferSequence &buffers, socket_base::message_flags flags, func_type complete_func)
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_send_op(socket_type socket, const ConstBufferSequence &buffers, socket_base::message_flags flags, Handler &handler)