Realistic 3D camera system
3D camera system components
wait_handler.hpp
Go to the documentation of this file.
1 //
2 // detail/wait_handler.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_WAIT_HANDLER_HPP
12 #define ASIO_DETAIL_WAIT_HANDLER_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"
23 #include "asio/detail/wait_op.hpp"
24 #include "asio/io_service.hpp"
25 
27 
28 namespace asio {
29 namespace detail {
30 
31 template <typename Handler>
32 class wait_handler : public wait_op
33 {
34 public:
36 
37  wait_handler(Handler& h)
39  handler_(ASIO_MOVE_CAST(Handler)(h))
40  {
41  }
42 
43  static void do_complete(io_service_impl* owner, operation* base,
44  const asio::error_code& /*ec*/,
45  std::size_t /*bytes_transferred*/)
46  {
47  // Take ownership of the handler object.
48  wait_handler* h(static_cast<wait_handler*>(base));
49  ptr p = { asio::detail::addressof(h->handler_), h, h };
50 
52 
53  // Make a copy of the handler so that the memory can be deallocated before
54  // the upcall is made. Even if we're not about to make an upcall, a
55  // sub-object of the handler may be the true owner of the memory associated
56  // with the handler. Consequently, a local copy of the handler is required
57  // to ensure that any owning sub-object remains valid until after we have
58  // deallocated the memory here.
60  handler(h->handler_, h->ec_);
61  p.h = asio::detail::addressof(handler.handler_);
62  p.reset();
63 
64  // Make the upcall if required.
65  if (owner)
66  {
71  }
72  }
73 
74 private:
75  Handler handler_;
76 };
77 
78 } // namespace detail
79 } // namespace asio
80 
82 
83 #endif // ASIO_DETAIL_WAIT_HANDLER_HPP
#define ASIO_HANDLER_INVOCATION_END
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)
#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
static void do_complete(io_service_impl *owner, operation *base, const asio::error_code &, std::size_t)
#define ASIO_HANDLER_COMPLETION(args)
#define ASIO_MOVE_CAST(type)
Definition: config.hpp:138
ASIO_DEFINE_HANDLER_PTR(wait_handler)