Realistic 3D camera system
3D camera system components
resolver_service.hpp
Go to the documentation of this file.
1 //
2 // detail/resolver_service.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_RESOLVER_SERVICE_HPP
12 #define ASIO_DETAIL_RESOLVER_SERVICE_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_RUNTIME)
21 
28 
30 
31 namespace asio {
32 namespace detail {
33 
34 template <typename Protocol>
36 {
37 public:
38  // The implementation type of the resolver. A cancellation token is used to
39  // indicate to the background thread that the operation has been cancelled.
41 
42  // The endpoint type.
43  typedef typename Protocol::endpoint endpoint_type;
44 
45  // The query type.
47 
48  // The iterator type.
50 
51  // Constructor.
53  : resolver_service_base(io_service)
54  {
55  }
56 
57  // Resolve a query to a list of entries.
58  iterator_type resolve(implementation_type&, const query_type& query,
59  asio::error_code& ec)
60  {
61  asio::detail::addrinfo_type* address_info = 0;
62 
63  socket_ops::getaddrinfo(query.host_name().c_str(),
64  query.service_name().c_str(), query.hints(), &address_info, ec);
65  auto_addrinfo auto_address_info(address_info);
66 
67  return ec ? iterator_type() : iterator_type::create(
68  address_info, query.host_name(), query.service_name());
69  }
70 
71  // Asynchronously resolve a query to a list of entries.
72  template <typename Handler>
73  void async_resolve(implementation_type& impl,
74  const query_type& query, Handler& handler)
75  {
76  // Allocate and construct an operation to wrap the handler.
78  typename op::ptr p = { asio::detail::addressof(handler),
80  sizeof(op), handler), 0 };
81  p.p = new (p.v) op(impl, query, io_service_impl_, handler);
82 
83  ASIO_HANDLER_CREATION((p.p, "resolver", &impl, "async_resolve"));
84 
85  start_resolve_op(p.p);
86  p.v = p.p = 0;
87  }
88 
89  // Resolve an endpoint to a list of entries.
90  iterator_type resolve(implementation_type&,
91  const endpoint_type& endpoint, asio::error_code& ec)
92  {
93  char host_name[NI_MAXHOST];
94  char service_name[NI_MAXSERV];
95  socket_ops::sync_getnameinfo(endpoint.data(), endpoint.size(),
96  host_name, NI_MAXHOST, service_name, NI_MAXSERV,
97  endpoint.protocol().type(), ec);
98 
99  return ec ? iterator_type() : iterator_type::create(
100  endpoint, host_name, service_name);
101  }
102 
103  // Asynchronously resolve an endpoint to a list of entries.
104  template <typename Handler>
105  void async_resolve(implementation_type& impl,
106  const endpoint_type& endpoint, Handler& handler)
107  {
108  // Allocate and construct an operation to wrap the handler.
110  typename op::ptr p = { asio::detail::addressof(handler),
112  sizeof(op), handler), 0 };
113  p.p = new (p.v) op(impl, endpoint, io_service_impl_, handler);
114 
115  ASIO_HANDLER_CREATION((p.p, "resolver", &impl, "async_resolve"));
116 
117  start_resolve_op(p.p);
118  p.v = p.p = 0;
119  }
120 };
121 
122 } // namespace detail
123 } // namespace asio
124 
126 
127 #endif // !defined(ASIO_WINDOWS_RUNTIME)
128 
129 #endif // ASIO_DETAIL_RESOLVER_SERVICE_HPP
static basic_resolver_iterator create(asio::detail::addrinfo_type *address_info, const std::string &host_name, const std::string &service_name)
Create an iterator from an addrinfo list returned by getaddrinfo.
const asio::detail::addrinfo_type & hints() const
Get the hints associated with the query.
shared_ptr< void > shared_cancel_token_type
Definition: socket_ops.hpp:62
Provides core I/O functionality.
Definition: io_service.hpp:184
void async_resolve(implementation_type &impl, const query_type &query, Handler &handler)
asio::ip::basic_resolver_query< Protocol > query_type
ASIO_DECL void start_resolve_op(operation *op)
addrinfo addrinfo_type
void async_resolve(implementation_type &impl, const endpoint_type &endpoint, Handler &handler)
iterator_type resolve(implementation_type &, const endpoint_type &endpoint, asio::error_code &ec)
Class to represent an error code value.
Definition: error_code.hpp:80
socket_ops::shared_cancel_token_type implementation_type
ASIO_DECL std::string host_name()
Get the current host name.
Definition: host_name.ipp:29
std::string host_name() const
Get the host name associated with the query.
std::string service_name() const
Get the service name associated with the query.
asio::error_code sync_getnameinfo(const socket_addr_type *addr, std::size_t addrlen, char *host, std::size_t hostlen, char *serv, std::size_t servlen, int sock_type, asio::error_code &ec)
void * allocate(std::size_t s, Handler &h)
asio::ip::basic_resolver_iterator< Protocol > iterator_type
#define ASIO_HANDLER_CREATION(args)
resolver_service(asio::io_service &io_service)
iterator_type resolve(implementation_type &, const query_type &query, asio::error_code &ec)
asio::error_code getaddrinfo(const char *host, const char *service, const addrinfo_type &hints, addrinfo_type **result, asio::error_code &ec)