resolver_service.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // resolver_service.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2010 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. #ifndef ASIO_IP_RESOLVER_SERVICE_HPP
  11. #define ASIO_IP_RESOLVER_SERVICE_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/push_options.hpp"
  16. #include "asio/error.hpp"
  17. #include "asio/io_service.hpp"
  18. #include "asio/ip/basic_resolver_iterator.hpp"
  19. #include "asio/ip/basic_resolver_query.hpp"
  20. #include "asio/detail/resolver_service.hpp"
  21. #include "asio/detail/service_base.hpp"
  22. namespace asio {
  23. namespace ip {
  24. /// Default service implementation for a resolver.
  25. template <typename InternetProtocol>
  26. class resolver_service
  27. #if defined(GENERATING_DOCUMENTATION)
  28. : public asio::io_service::service
  29. #else
  30. : public asio::detail::service_base<
  31. resolver_service<InternetProtocol> >
  32. #endif
  33. {
  34. public:
  35. #if defined(GENERATING_DOCUMENTATION)
  36. /// The unique service identifier.
  37. static asio::io_service::id id;
  38. #endif
  39. /// The protocol type.
  40. typedef InternetProtocol protocol_type;
  41. /// The endpoint type.
  42. typedef typename InternetProtocol::endpoint endpoint_type;
  43. /// The query type.
  44. typedef basic_resolver_query<InternetProtocol> query_type;
  45. /// The iterator type.
  46. typedef basic_resolver_iterator<InternetProtocol> iterator_type;
  47. private:
  48. // The type of the platform-specific implementation.
  49. typedef asio::detail::resolver_service<InternetProtocol>
  50. service_impl_type;
  51. public:
  52. /// The type of a resolver implementation.
  53. #if defined(GENERATING_DOCUMENTATION)
  54. typedef implementation_defined implementation_type;
  55. #else
  56. typedef typename service_impl_type::implementation_type implementation_type;
  57. #endif
  58. /// Construct a new resolver service for the specified io_service.
  59. explicit resolver_service(asio::io_service& io_service)
  60. : asio::detail::service_base<
  61. resolver_service<InternetProtocol> >(io_service),
  62. service_impl_(asio::use_service<service_impl_type>(io_service))
  63. {
  64. }
  65. /// Destroy all user-defined handler objects owned by the service.
  66. void shutdown_service()
  67. {
  68. }
  69. /// Construct a new resolver implementation.
  70. void construct(implementation_type& impl)
  71. {
  72. service_impl_.construct(impl);
  73. }
  74. /// Destroy a resolver implementation.
  75. void destroy(implementation_type& impl)
  76. {
  77. service_impl_.destroy(impl);
  78. }
  79. /// Cancel pending asynchronous operations.
  80. void cancel(implementation_type& impl)
  81. {
  82. service_impl_.cancel(impl);
  83. }
  84. /// Resolve a query to a list of entries.
  85. iterator_type resolve(implementation_type& impl, const query_type& query,
  86. asio::error_code& ec)
  87. {
  88. return service_impl_.resolve(impl, query, ec);
  89. }
  90. /// Asynchronously resolve a query to a list of entries.
  91. template <typename Handler>
  92. void async_resolve(implementation_type& impl, const query_type& query,
  93. Handler handler)
  94. {
  95. service_impl_.async_resolve(impl, query, handler);
  96. }
  97. /// Resolve an endpoint to a list of entries.
  98. iterator_type resolve(implementation_type& impl,
  99. const endpoint_type& endpoint, asio::error_code& ec)
  100. {
  101. return service_impl_.resolve(impl, endpoint, ec);
  102. }
  103. /// Asynchronously resolve an endpoint to a list of entries.
  104. template <typename ResolveHandler>
  105. void async_resolve(implementation_type& impl, const endpoint_type& endpoint,
  106. ResolveHandler handler)
  107. {
  108. return service_impl_.async_resolve(impl, endpoint, handler);
  109. }
  110. private:
  111. // The service that provides the platform-specific implementation.
  112. service_impl_type& service_impl_;
  113. };
  114. } // namespace ip
  115. } // namespace asio
  116. #include "asio/detail/pop_options.hpp"
  117. #endif // ASIO_IP_RESOLVER_SERVICE_HPP