Realistic 3D camera system
3D camera system components
descriptor_write_op.hpp
Go to the documentation of this file.
1 //
2 // detail/descriptor_write_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_DESCRIPTOR_WRITE_OP_HPP
12 #define ASIO_DETAIL_DESCRIPTOR_WRITE_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_WINDOWS) && !defined(__CYGWIN__)
21 
28 
30 
31 namespace asio {
32 namespace detail {
33 
34 template <typename ConstBufferSequence>
36 {
37 public:
38  descriptor_write_op_base(int descriptor,
39  const ConstBufferSequence& buffers, func_type complete_func)
41  descriptor_(descriptor),
42  buffers_(buffers)
43  {
44  }
45 
46  static bool do_perform(reactor_op* base)
47  {
48  descriptor_write_op_base* o(static_cast<descriptor_write_op_base*>(base));
49 
51  ConstBufferSequence> bufs(o->buffers_);
52 
53  return descriptor_ops::non_blocking_write(o->descriptor_,
54  bufs.buffers(), bufs.count(), o->ec_, o->bytes_transferred_);
55  }
56 
57 private:
58  int descriptor_;
59  ConstBufferSequence buffers_;
60 };
61 
62 template <typename ConstBufferSequence, typename Handler>
64  : public descriptor_write_op_base<ConstBufferSequence>
65 {
66 public:
68 
69  descriptor_write_op(int descriptor,
70  const ConstBufferSequence& buffers, Handler& handler)
71  : descriptor_write_op_base<ConstBufferSequence>(
72  descriptor, buffers, &descriptor_write_op::do_complete),
73  handler_(ASIO_MOVE_CAST(Handler)(handler))
74  {
75  }
76 
77  static void do_complete(io_service_impl* owner, operation* base,
78  const asio::error_code& /*ec*/,
79  std::size_t /*bytes_transferred*/)
80  {
81  // Take ownership of the handler object.
82  descriptor_write_op* o(static_cast<descriptor_write_op*>(base));
83  ptr p = { asio::detail::addressof(o->handler_), o, o };
84 
86 
87  // Make a copy of the handler so that the memory can be deallocated before
88  // the upcall is made. Even if we're not about to make an upcall, a
89  // sub-object of the handler may be the true owner of the memory associated
90  // with the handler. Consequently, a local copy of the handler is required
91  // to ensure that any owning sub-object remains valid until after we have
92  // deallocated the memory here.
94  handler(o->handler_, o->ec_, o->bytes_transferred_);
95  p.h = asio::detail::addressof(handler.handler_);
96  p.reset();
97 
98  // Make the upcall if required.
99  if (owner)
100  {
102  ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, handler.arg2_));
105  }
106  }
107 
108 private:
109  Handler handler_;
110 };
111 
112 } // namespace detail
113 } // namespace asio
114 
116 
117 #endif // !defined(ASIO_WINDOWS) && !defined(__CYGWIN__)
118 
119 #endif // ASIO_DETAIL_DESCRIPTOR_WRITE_OP_HPP
#define ASIO_HANDLER_INVOCATION_END
Holds a buffer that cannot be modified.
Definition: buffer.hpp:211
descriptor_write_op_base(int descriptor, const ConstBufferSequence &buffers, func_type complete_func)
descriptor_write_op(int descriptor, const ConstBufferSequence &buffers, Handler &handler)
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)
static bool do_perform(reactor_op *base)
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
ASIO_DECL bool non_blocking_write(int d, const buf *bufs, std::size_t count, asio::error_code &ec, std::size_t &bytes_transferred)
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
static void do_complete(io_service_impl *owner, operation *base, const asio::error_code &, std::size_t)
#define ASIO_DEFINE_HANDLER_PTR(op)
#define ASIO_HANDLER_COMPLETION(args)
#define ASIO_MOVE_CAST(type)
Definition: config.hpp:138