resolver_service.hpp 3.9 KB

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