Realistic 3D camera system
3D camera system components
reactive_socket_sendto_op.hpp
Go to the documentation of this file.
1 //
2 // detail/reactive_socket_sendto_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_SENDTO_OP_HPP
12 #define ASIO_DETAIL_REACTIVE_SOCKET_SENDTO_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, typename Endpoint>
33 {
34 public:
36  const ConstBufferSequence& buffers, const Endpoint& endpoint,
37  socket_base::message_flags flags, func_type complete_func)
39  socket_(socket),
40  buffers_(buffers),
41  destination_(endpoint),
42  flags_(flags)
43  {
44  }
45 
46  static bool do_perform(reactor_op* base)
47  {
49  static_cast<reactive_socket_sendto_op_base*>(base));
50 
52  ConstBufferSequence> bufs(o->buffers_);
53 
54  return socket_ops::non_blocking_sendto(o->socket_,
55  bufs.buffers(), bufs.count(), o->flags_,
56  o->destination_.data(), o->destination_.size(),
57  o->ec_, o->bytes_transferred_);
58  }
59 
60 private:
61  socket_type socket_;
62  ConstBufferSequence buffers_;
63  Endpoint destination_;
65 };
66 
67 template <typename ConstBufferSequence, typename Endpoint, typename Handler>
69  public reactive_socket_sendto_op_base<ConstBufferSequence, Endpoint>
70 {
71 public:
73 
75  const ConstBufferSequence& buffers, const Endpoint& endpoint,
76  socket_base::message_flags flags, Handler& handler)
77  : reactive_socket_sendto_op_base<ConstBufferSequence, Endpoint>(socket,
78  buffers, endpoint, flags, &reactive_socket_sendto_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_sendto_op* o(static_cast<reactive_socket_sendto_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_SENDTO_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_sendto_op_base(socket_type socket, const ConstBufferSequence &buffers, const Endpoint &endpoint, socket_base::message_flags flags, func_type complete_func)
Holds a buffer that cannot be modified.
Definition: buffer.hpp:211
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
void invoke(Function &function, Context &context)
const MutableBufferSequence & buffers
Definition: read.hpp:521
bool non_blocking_sendto(socket_type s, const buf *bufs, size_t count, int flags, const socket_addr_type *addr, std::size_t addrlen, 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
static void do_complete(io_service_impl *owner, operation *base, const asio::error_code &, std::size_t)
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_sendto_op(socket_type socket, const ConstBufferSequence &buffers, const Endpoint &endpoint, socket_base::message_flags flags, Handler &handler)