resolver_base.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // ip/resolver_base.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2024 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_BASE_HPP
  11. #define BOOST_ASIO_IP_RESOLVER_BASE_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/config.hpp>
  16. #include <boost/asio/detail/socket_types.hpp>
  17. #include <boost/asio/detail/push_options.hpp>
  18. namespace boost {
  19. namespace asio {
  20. namespace ip {
  21. /// The resolver_base class is used as a base for the basic_resolver class
  22. /// templates to provide a common place to define the flag constants.
  23. class resolver_base
  24. {
  25. public:
  26. #if defined(GENERATING_DOCUMENTATION)
  27. /// A bitmask type (C++ Std [lib.bitmask.types]).
  28. typedef unspecified flags;
  29. /// Determine the canonical name of the host specified in the query.
  30. static const flags canonical_name = implementation_defined;
  31. /// Indicate that returned endpoint is intended for use as a locally bound
  32. /// socket endpoint.
  33. static const flags passive = implementation_defined;
  34. /// Host name should be treated as a numeric string defining an IPv4 or IPv6
  35. /// address and no name resolution should be attempted.
  36. static const flags numeric_host = implementation_defined;
  37. /// Service name should be treated as a numeric string defining a port number
  38. /// and no name resolution should be attempted.
  39. static const flags numeric_service = implementation_defined;
  40. /// If the query protocol family is specified as IPv6, return IPv4-mapped
  41. /// IPv6 addresses on finding no IPv6 addresses.
  42. static const flags v4_mapped = implementation_defined;
  43. /// If used with v4_mapped, return all matching IPv6 and IPv4 addresses.
  44. static const flags all_matching = implementation_defined;
  45. /// Only return IPv4 addresses if a non-loopback IPv4 address is configured
  46. /// for the system. Only return IPv6 addresses if a non-loopback IPv6 address
  47. /// is configured for the system.
  48. static const flags address_configured = implementation_defined;
  49. #else
  50. enum flags
  51. {
  52. canonical_name = BOOST_ASIO_OS_DEF(AI_CANONNAME),
  53. passive = BOOST_ASIO_OS_DEF(AI_PASSIVE),
  54. numeric_host = BOOST_ASIO_OS_DEF(AI_NUMERICHOST),
  55. numeric_service = BOOST_ASIO_OS_DEF(AI_NUMERICSERV),
  56. v4_mapped = BOOST_ASIO_OS_DEF(AI_V4MAPPED),
  57. all_matching = BOOST_ASIO_OS_DEF(AI_ALL),
  58. address_configured = BOOST_ASIO_OS_DEF(AI_ADDRCONFIG)
  59. };
  60. // Implement bitmask operations as shown in C++ Std [lib.bitmask.types].
  61. friend flags operator&(flags x, flags y)
  62. {
  63. return static_cast<flags>(
  64. static_cast<unsigned int>(x) & static_cast<unsigned int>(y));
  65. }
  66. friend flags operator|(flags x, flags y)
  67. {
  68. return static_cast<flags>(
  69. static_cast<unsigned int>(x) | static_cast<unsigned int>(y));
  70. }
  71. friend flags operator^(flags x, flags y)
  72. {
  73. return static_cast<flags>(
  74. static_cast<unsigned int>(x) ^ static_cast<unsigned int>(y));
  75. }
  76. friend flags operator~(flags x)
  77. {
  78. return static_cast<flags>(~static_cast<unsigned int>(x));
  79. }
  80. friend flags& operator&=(flags& x, flags y)
  81. {
  82. x = x & y;
  83. return x;
  84. }
  85. friend flags& operator|=(flags& x, flags y)
  86. {
  87. x = x | y;
  88. return x;
  89. }
  90. friend flags& operator^=(flags& x, flags y)
  91. {
  92. x = x ^ y;
  93. return x;
  94. }
  95. #endif
  96. protected:
  97. /// Protected destructor to prevent deletion through this type.
  98. ~resolver_base()
  99. {
  100. }
  101. };
  102. } // namespace ip
  103. } // namespace asio
  104. } // namespace boost
  105. #include <boost/asio/detail/pop_options.hpp>
  106. #endif // BOOST_ASIO_IP_RESOLVER_BASE_HPP