basic_resolver_query.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. //
  2. // basic_resolver_query.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_BASIC_RESOLVER_QUERY_HPP
  11. #define BOOST_ASIO_IP_BASIC_RESOLVER_QUERY_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/detail/push_options.hpp>
  17. #include <boost/config.hpp>
  18. #include <string>
  19. #include <boost/asio/detail/pop_options.hpp>
  20. #include <boost/asio/detail/socket_ops.hpp>
  21. #include <boost/asio/ip/resolver_query_base.hpp>
  22. namespace boost {
  23. namespace asio {
  24. namespace ip {
  25. /// An query to be passed to a resolver.
  26. /**
  27. * The boost::asio::ip::basic_resolver_query class template describes a query
  28. * that can be passed to a resolver.
  29. *
  30. * @par Thread Safety
  31. * @e Distinct @e objects: Safe.@n
  32. * @e Shared @e objects: Unsafe.
  33. */
  34. template <typename InternetProtocol>
  35. class basic_resolver_query
  36. : public resolver_query_base
  37. {
  38. public:
  39. /// The protocol type associated with the endpoint query.
  40. typedef InternetProtocol protocol_type;
  41. /// Construct with specified service name for any protocol.
  42. basic_resolver_query(const std::string& service_name,
  43. int flags = passive | address_configured)
  44. : hints_(),
  45. host_name_(),
  46. service_name_(service_name)
  47. {
  48. typename InternetProtocol::endpoint endpoint;
  49. hints_.ai_flags = flags;
  50. hints_.ai_family = PF_UNSPEC;
  51. hints_.ai_socktype = endpoint.protocol().type();
  52. hints_.ai_protocol = endpoint.protocol().protocol();
  53. hints_.ai_addrlen = 0;
  54. hints_.ai_canonname = 0;
  55. hints_.ai_addr = 0;
  56. hints_.ai_next = 0;
  57. }
  58. /// Construct with specified service name for a given protocol.
  59. basic_resolver_query(const protocol_type& protocol,
  60. const std::string& service_name,
  61. int flags = passive | address_configured)
  62. : hints_(),
  63. host_name_(),
  64. service_name_(service_name)
  65. {
  66. hints_.ai_flags = flags;
  67. hints_.ai_family = protocol.family();
  68. hints_.ai_socktype = protocol.type();
  69. hints_.ai_protocol = protocol.protocol();
  70. hints_.ai_addrlen = 0;
  71. hints_.ai_canonname = 0;
  72. hints_.ai_addr = 0;
  73. hints_.ai_next = 0;
  74. }
  75. /// Construct with specified host name and service name for any protocol.
  76. basic_resolver_query(const std::string& host_name,
  77. const std::string& service_name, int flags = address_configured)
  78. : hints_(),
  79. host_name_(host_name),
  80. service_name_(service_name)
  81. {
  82. typename InternetProtocol::endpoint endpoint;
  83. hints_.ai_flags = flags;
  84. hints_.ai_family = PF_UNSPEC;
  85. hints_.ai_socktype = endpoint.protocol().type();
  86. hints_.ai_protocol = endpoint.protocol().protocol();
  87. hints_.ai_addrlen = 0;
  88. hints_.ai_canonname = 0;
  89. hints_.ai_addr = 0;
  90. hints_.ai_next = 0;
  91. }
  92. /// Construct with specified host name and service name for a given protocol.
  93. basic_resolver_query(const protocol_type& protocol,
  94. const std::string& host_name, const std::string& service_name,
  95. int flags = address_configured)
  96. : hints_(),
  97. host_name_(host_name),
  98. service_name_(service_name)
  99. {
  100. hints_.ai_flags = flags;
  101. hints_.ai_family = protocol.family();
  102. hints_.ai_socktype = protocol.type();
  103. hints_.ai_protocol = protocol.protocol();
  104. hints_.ai_addrlen = 0;
  105. hints_.ai_canonname = 0;
  106. hints_.ai_addr = 0;
  107. hints_.ai_next = 0;
  108. }
  109. /// Get the hints associated with the query.
  110. const boost::asio::detail::addrinfo_type& hints() const
  111. {
  112. return hints_;
  113. }
  114. /// Get the host name associated with the query.
  115. std::string host_name() const
  116. {
  117. return host_name_;
  118. }
  119. /// Get the service name associated with the query.
  120. std::string service_name() const
  121. {
  122. return service_name_;
  123. }
  124. private:
  125. boost::asio::detail::addrinfo_type hints_;
  126. std::string host_name_;
  127. std::string service_name_;
  128. };
  129. } // namespace ip
  130. } // namespace asio
  131. } // namespace boost
  132. #include <boost/asio/detail/pop_options.hpp>
  133. #endif // BOOST_ASIO_IP_BASIC_RESOLVER_QUERY_HPP