Realistic 3D camera system
3D camera system components
reactive_socket_connect_op.hpp
Go to the documentation of this file.
1 //
2 // detail/reactive_socket_connect_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_CONNECT_OP_HPP
12 #define ASIO_DETAIL_REACTIVE_SOCKET_CONNECT_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 
32 {
33 public:
36  socket_(socket)
37  {
38  }
39 
40  static bool do_perform(reactor_op* base)
41  {
43  static_cast<reactive_socket_connect_op_base*>(base));
44 
45  return socket_ops::non_blocking_connect(o->socket_, o->ec_);
46  }
47 
48 private:
49  socket_type socket_;
50 };
51 
52 template <typename Handler>
54 {
55 public:
57 
60  &reactive_socket_connect_op::do_complete),
61  handler_(ASIO_MOVE_CAST(Handler)(handler))
62  {
63  }
64 
65  static void do_complete(io_service_impl* owner, operation* base,
66  const asio::error_code& /*ec*/,
67  std::size_t /*bytes_transferred*/)
68  {
69  // Take ownership of the handler object.
71  (static_cast<reactive_socket_connect_op*>(base));
72  ptr p = { asio::detail::addressof(o->handler_), o, o };
73 
75 
76  // Make a copy of the handler so that the memory can be deallocated before
77  // the upcall is made. Even if we're not about to make an upcall, a
78  // sub-object of the handler may be the true owner of the memory associated
79  // with the handler. Consequently, a local copy of the handler is required
80  // to ensure that any owning sub-object remains valid until after we have
81  // deallocated the memory here.
83  handler(o->handler_, o->ec_);
84  p.h = asio::detail::addressof(handler.handler_);
85  p.reset();
86 
87  // Make the upcall if required.
88  if (owner)
89  {
92  asio_handler_invoke_helpers::invoke(handler, handler);
94  }
95  }
96 
97 private:
98  Handler handler_;
99 };
100 
101 } // namespace detail
102 } // namespace asio
103 
105 
106 #endif // ASIO_DETAIL_REACTIVE_SOCKET_CONNECT_OP_HPP
#define ASIO_HANDLER_INVOCATION_END
static void do_complete(io_service_impl *owner, operation *base, const asio::error_code &, std::size_t)
reactive_socket_connect_op_base(socket_type socket, func_type complete_func)
socket_type socket(int af, int type, int protocol, asio::error_code &ec)
reactive_socket_connect_op(socket_type socket, 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)
#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
#define ASIO_DEFINE_HANDLER_PTR(op)
#define ASIO_HANDLER_COMPLETION(args)
#define ASIO_MOVE_CAST(type)
Definition: config.hpp:138
bool non_blocking_connect(socket_type s, asio::error_code &ec)
Definition: socket_ops.ipp:559