Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / asio / detail / resolve_op.hpp @ 2486

History | View | Annotate | Download (4.3 kB)

1 2486 sjacqu01
//
2 2486 sjacqu01
// detail/resolve_op.hpp
3 2486 sjacqu01
// ~~~~~~~~~~~~~~~~~~~~~
4 2486 sjacqu01
//
5 2486 sjacqu01
// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 2486 sjacqu01
//
7 2486 sjacqu01
// Distributed under the Boost Software License, Version 1.0. (See accompanying
8 2486 sjacqu01
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 2486 sjacqu01
//
10 2486 sjacqu01
11 2486 sjacqu01
#ifndef BOOST_ASIO_DETAIL_RESOLVE_OP_HPP
12 2486 sjacqu01
#define BOOST_ASIO_DETAIL_RESOLVE_OP_HPP
13 2486 sjacqu01
14 2486 sjacqu01
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 2486 sjacqu01
# pragma once
16 2486 sjacqu01
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 2486 sjacqu01
18 2486 sjacqu01
#include <boost/asio/detail/config.hpp>
19 2486 sjacqu01
#include <boost/asio/error.hpp>
20 2486 sjacqu01
#include <boost/asio/io_service.hpp>
21 2486 sjacqu01
#include <boost/asio/ip/basic_resolver_iterator.hpp>
22 2486 sjacqu01
#include <boost/asio/ip/basic_resolver_query.hpp>
23 2486 sjacqu01
#include <boost/asio/detail/addressof.hpp>
24 2486 sjacqu01
#include <boost/asio/detail/bind_handler.hpp>
25 2486 sjacqu01
#include <boost/asio/detail/fenced_block.hpp>
26 2486 sjacqu01
#include <boost/asio/detail/handler_alloc_helpers.hpp>
27 2486 sjacqu01
#include <boost/asio/detail/handler_invoke_helpers.hpp>
28 2486 sjacqu01
#include <boost/asio/detail/operation.hpp>
29 2486 sjacqu01
#include <boost/asio/detail/socket_ops.hpp>
30 2486 sjacqu01
31 2486 sjacqu01
#include <boost/asio/detail/push_options.hpp>
32 2486 sjacqu01
33 2486 sjacqu01
namespace boost {
34 2486 sjacqu01
namespace asio {
35 2486 sjacqu01
namespace detail {
36 2486 sjacqu01
37 2486 sjacqu01
template <typename Protocol, typename Handler>
38 2486 sjacqu01
class resolve_op : public operation
39 2486 sjacqu01
{
40 2486 sjacqu01
public:
41 2486 sjacqu01
  BOOST_ASIO_DEFINE_HANDLER_PTR(resolve_op);
42 2486 sjacqu01
43 2486 sjacqu01
  typedef boost::asio::ip::basic_resolver_query<Protocol> query_type;
44 2486 sjacqu01
  typedef boost::asio::ip::basic_resolver_iterator<Protocol> iterator_type;
45 2486 sjacqu01
46 2486 sjacqu01
  resolve_op(socket_ops::weak_cancel_token_type cancel_token,
47 2486 sjacqu01
      const query_type& query, io_service_impl& ios, Handler& handler)
48 2486 sjacqu01
    : operation(&resolve_op::do_complete),
49 2486 sjacqu01
      cancel_token_(cancel_token),
50 2486 sjacqu01
      query_(query),
51 2486 sjacqu01
      io_service_impl_(ios),
52 2486 sjacqu01
      handler_(BOOST_ASIO_MOVE_CAST(Handler)(handler)),
53 2486 sjacqu01
      addrinfo_(0)
54 2486 sjacqu01
  {
55 2486 sjacqu01
  }
56 2486 sjacqu01
57 2486 sjacqu01
  ~resolve_op()
58 2486 sjacqu01
  {
59 2486 sjacqu01
    if (addrinfo_)
60 2486 sjacqu01
      socket_ops::freeaddrinfo(addrinfo_);
61 2486 sjacqu01
  }
62 2486 sjacqu01
63 2486 sjacqu01
  static void do_complete(io_service_impl* owner, operation* base,
64 2486 sjacqu01
      const boost::system::error_code& /*ec*/,
65 2486 sjacqu01
      std::size_t /*bytes_transferred*/)
66 2486 sjacqu01
  {
67 2486 sjacqu01
    // Take ownership of the operation object.
68 2486 sjacqu01
    resolve_op* o(static_cast<resolve_op*>(base));
69 2486 sjacqu01
    ptr p = { boost::asio::detail::addressof(o->handler_), o, o };
70 2486 sjacqu01
71 2486 sjacqu01
    if (owner && owner != &o->io_service_impl_)
72 2486 sjacqu01
    {
73 2486 sjacqu01
      // The operation is being run on the worker io_service. Time to perform
74 2486 sjacqu01
      // the resolver operation.
75 2486 sjacqu01
76 2486 sjacqu01
      // Perform the blocking host resolution operation.
77 2486 sjacqu01
      socket_ops::background_getaddrinfo(o->cancel_token_,
78 2486 sjacqu01
          o->query_.host_name().c_str(), o->query_.service_name().c_str(),
79 2486 sjacqu01
          o->query_.hints(), &o->addrinfo_, o->ec_);
80 2486 sjacqu01
81 2486 sjacqu01
      // Pass operation back to main io_service for completion.
82 2486 sjacqu01
      o->io_service_impl_.post_deferred_completion(o);
83 2486 sjacqu01
      p.v = p.p = 0;
84 2486 sjacqu01
    }
85 2486 sjacqu01
    else
86 2486 sjacqu01
    {
87 2486 sjacqu01
      // The operation has been returned to the main io_service. The completion
88 2486 sjacqu01
      // handler is ready to be delivered.
89 2486 sjacqu01
90 2486 sjacqu01
      BOOST_ASIO_HANDLER_COMPLETION((o));
91 2486 sjacqu01
92 2486 sjacqu01
      // Make a copy of the handler so that the memory can be deallocated
93 2486 sjacqu01
      // before the upcall is made. Even if we're not about to make an upcall,
94 2486 sjacqu01
      // a sub-object of the handler may be the true owner of the memory
95 2486 sjacqu01
      // associated with the handler. Consequently, a local copy of the handler
96 2486 sjacqu01
      // is required to ensure that any owning sub-object remains valid until
97 2486 sjacqu01
      // after we have deallocated the memory here.
98 2486 sjacqu01
      detail::binder2<Handler, boost::system::error_code, iterator_type>
99 2486 sjacqu01
        handler(o->handler_, o->ec_, iterator_type());
100 2486 sjacqu01
      p.h = boost::asio::detail::addressof(handler.handler_);
101 2486 sjacqu01
      if (o->addrinfo_)
102 2486 sjacqu01
      {
103 2486 sjacqu01
        handler.arg2_ = iterator_type::create(o->addrinfo_,
104 2486 sjacqu01
            o->query_.host_name(), o->query_.service_name());
105 2486 sjacqu01
      }
106 2486 sjacqu01
      p.reset();
107 2486 sjacqu01
108 2486 sjacqu01
      if (owner)
109 2486 sjacqu01
      {
110 2486 sjacqu01
        fenced_block b(fenced_block::half);
111 2486 sjacqu01
        BOOST_ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, "..."));
112 2486 sjacqu01
        boost_asio_handler_invoke_helpers::invoke(handler, handler.handler_);
113 2486 sjacqu01
        BOOST_ASIO_HANDLER_INVOCATION_END;
114 2486 sjacqu01
      }
115 2486 sjacqu01
    }
116 2486 sjacqu01
  }
117 2486 sjacqu01
118 2486 sjacqu01
private:
119 2486 sjacqu01
  socket_ops::weak_cancel_token_type cancel_token_;
120 2486 sjacqu01
  query_type query_;
121 2486 sjacqu01
  io_service_impl& io_service_impl_;
122 2486 sjacqu01
  Handler handler_;
123 2486 sjacqu01
  boost::system::error_code ec_;
124 2486 sjacqu01
  boost::asio::detail::addrinfo_type* addrinfo_;
125 2486 sjacqu01
};
126 2486 sjacqu01
127 2486 sjacqu01
} // namespace detail
128 2486 sjacqu01
} // namespace asio
129 2486 sjacqu01
} // namespace boost
130 2486 sjacqu01
131 2486 sjacqu01
#include <boost/asio/detail/pop_options.hpp>
132 2486 sjacqu01
133 2486 sjacqu01
#endif // BOOST_ASIO_DETAIL_RESOLVE_OP_HPP