Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

245 lines
9.0KB

  1. //
  2. // ip/basic_resolver_query.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 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_BASIC_RESOLVER_QUERY_HPP
  11. #define 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 "asio/detail/config.hpp"
  16. #include <string>
  17. #include "asio/detail/socket_ops.hpp"
  18. #include "asio/ip/resolver_query_base.hpp"
  19. #include "asio/detail/push_options.hpp"
  20. namespace asio {
  21. namespace ip {
  22. /// An query to be passed to a resolver.
  23. /**
  24. * The asio::ip::basic_resolver_query class template describes a query
  25. * that can be passed to a resolver.
  26. *
  27. * @par Thread Safety
  28. * @e Distinct @e objects: Safe.@n
  29. * @e Shared @e objects: Unsafe.
  30. */
  31. template <typename InternetProtocol>
  32. class basic_resolver_query
  33. : public resolver_query_base
  34. {
  35. public:
  36. /// The protocol type associated with the endpoint query.
  37. typedef InternetProtocol protocol_type;
  38. /// Construct with specified service name for any protocol.
  39. /**
  40. * This constructor is typically used to perform name resolution for local
  41. * service binding.
  42. *
  43. * @param service A string identifying the requested service. This may be a
  44. * descriptive name or a numeric string corresponding to a port number.
  45. *
  46. * @param resolve_flags A set of flags that determine how name resolution
  47. * should be performed. The default flags are suitable for local service
  48. * binding.
  49. *
  50. * @note On POSIX systems, service names are typically defined in the file
  51. * <tt>/etc/services</tt>. On Windows, service names may be found in the file
  52. * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
  53. * may use additional locations when resolving service names.
  54. */
  55. basic_resolver_query(const std::string& service,
  56. resolver_query_base::flags resolve_flags = passive | address_configured)
  57. : hints_(),
  58. host_name_(),
  59. service_name_(service)
  60. {
  61. typename InternetProtocol::endpoint endpoint;
  62. hints_.ai_flags = static_cast<int>(resolve_flags);
  63. hints_.ai_family = PF_UNSPEC;
  64. hints_.ai_socktype = endpoint.protocol().type();
  65. hints_.ai_protocol = endpoint.protocol().protocol();
  66. hints_.ai_addrlen = 0;
  67. hints_.ai_canonname = 0;
  68. hints_.ai_addr = 0;
  69. hints_.ai_next = 0;
  70. }
  71. /// Construct with specified service name for a given protocol.
  72. /**
  73. * This constructor is typically used to perform name resolution for local
  74. * service binding with a specific protocol version.
  75. *
  76. * @param protocol A protocol object, normally representing either the IPv4 or
  77. * IPv6 version of an internet protocol.
  78. *
  79. * @param service A string identifying the requested service. This may be a
  80. * descriptive name or a numeric string corresponding to a port number.
  81. *
  82. * @param resolve_flags A set of flags that determine how name resolution
  83. * should be performed. The default flags are suitable for local service
  84. * binding.
  85. *
  86. * @note On POSIX systems, service names are typically defined in the file
  87. * <tt>/etc/services</tt>. On Windows, service names may be found in the file
  88. * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
  89. * may use additional locations when resolving service names.
  90. */
  91. basic_resolver_query(const protocol_type& protocol,
  92. const std::string& service,
  93. resolver_query_base::flags resolve_flags = passive | address_configured)
  94. : hints_(),
  95. host_name_(),
  96. service_name_(service)
  97. {
  98. hints_.ai_flags = static_cast<int>(resolve_flags);
  99. hints_.ai_family = protocol.family();
  100. hints_.ai_socktype = protocol.type();
  101. hints_.ai_protocol = protocol.protocol();
  102. hints_.ai_addrlen = 0;
  103. hints_.ai_canonname = 0;
  104. hints_.ai_addr = 0;
  105. hints_.ai_next = 0;
  106. }
  107. /// Construct with specified host name and service name for any protocol.
  108. /**
  109. * This constructor is typically used to perform name resolution for
  110. * communication with remote hosts.
  111. *
  112. * @param host A string identifying a location. May be a descriptive name or
  113. * a numeric address string. If an empty string and the passive flag has been
  114. * specified, the resolved endpoints are suitable for local service binding.
  115. * If an empty string and passive is not specified, the resolved endpoints
  116. * will use the loopback address.
  117. *
  118. * @param service A string identifying the requested service. This may be a
  119. * descriptive name or a numeric string corresponding to a port number. May
  120. * be an empty string, in which case all resolved endpoints will have a port
  121. * number of 0.
  122. *
  123. * @param resolve_flags A set of flags that determine how name resolution
  124. * should be performed. The default flags are suitable for communication with
  125. * remote hosts.
  126. *
  127. * @note On POSIX systems, host names may be locally defined in the file
  128. * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
  129. * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
  130. * resolution is performed using DNS. Operating systems may use additional
  131. * locations when resolving host names (such as NETBIOS names on Windows).
  132. *
  133. * On POSIX systems, service names are typically defined in the file
  134. * <tt>/etc/services</tt>. On Windows, service names may be found in the file
  135. * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
  136. * may use additional locations when resolving service names.
  137. */
  138. basic_resolver_query(const std::string& host, const std::string& service,
  139. resolver_query_base::flags resolve_flags = address_configured)
  140. : hints_(),
  141. host_name_(host),
  142. service_name_(service)
  143. {
  144. typename InternetProtocol::endpoint endpoint;
  145. hints_.ai_flags = static_cast<int>(resolve_flags);
  146. hints_.ai_family = ASIO_OS_DEF(AF_UNSPEC);
  147. hints_.ai_socktype = endpoint.protocol().type();
  148. hints_.ai_protocol = endpoint.protocol().protocol();
  149. hints_.ai_addrlen = 0;
  150. hints_.ai_canonname = 0;
  151. hints_.ai_addr = 0;
  152. hints_.ai_next = 0;
  153. }
  154. /// Construct with specified host name and service name for a given protocol.
  155. /**
  156. * This constructor is typically used to perform name resolution for
  157. * communication with remote hosts.
  158. *
  159. * @param protocol A protocol object, normally representing either the IPv4 or
  160. * IPv6 version of an internet protocol.
  161. *
  162. * @param host A string identifying a location. May be a descriptive name or
  163. * a numeric address string. If an empty string and the passive flag has been
  164. * specified, the resolved endpoints are suitable for local service binding.
  165. * If an empty string and passive is not specified, the resolved endpoints
  166. * will use the loopback address.
  167. *
  168. * @param service A string identifying the requested service. This may be a
  169. * descriptive name or a numeric string corresponding to a port number. May
  170. * be an empty string, in which case all resolved endpoints will have a port
  171. * number of 0.
  172. *
  173. * @param resolve_flags A set of flags that determine how name resolution
  174. * should be performed. The default flags are suitable for communication with
  175. * remote hosts.
  176. *
  177. * @note On POSIX systems, host names may be locally defined in the file
  178. * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
  179. * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
  180. * resolution is performed using DNS. Operating systems may use additional
  181. * locations when resolving host names (such as NETBIOS names on Windows).
  182. *
  183. * On POSIX systems, service names are typically defined in the file
  184. * <tt>/etc/services</tt>. On Windows, service names may be found in the file
  185. * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
  186. * may use additional locations when resolving service names.
  187. */
  188. basic_resolver_query(const protocol_type& protocol,
  189. const std::string& host, const std::string& service,
  190. resolver_query_base::flags resolve_flags = address_configured)
  191. : hints_(),
  192. host_name_(host),
  193. service_name_(service)
  194. {
  195. hints_.ai_flags = static_cast<int>(resolve_flags);
  196. hints_.ai_family = protocol.family();
  197. hints_.ai_socktype = protocol.type();
  198. hints_.ai_protocol = protocol.protocol();
  199. hints_.ai_addrlen = 0;
  200. hints_.ai_canonname = 0;
  201. hints_.ai_addr = 0;
  202. hints_.ai_next = 0;
  203. }
  204. /// Get the hints associated with the query.
  205. const asio::detail::addrinfo_type& hints() const
  206. {
  207. return hints_;
  208. }
  209. /// Get the host name associated with the query.
  210. std::string host_name() const
  211. {
  212. return host_name_;
  213. }
  214. /// Get the service name associated with the query.
  215. std::string service_name() const
  216. {
  217. return service_name_;
  218. }
  219. private:
  220. asio::detail::addrinfo_type hints_;
  221. std::string host_name_;
  222. std::string service_name_;
  223. };
  224. } // namespace ip
  225. } // namespace asio
  226. #include "asio/detail/pop_options.hpp"
  227. #endif // ASIO_IP_BASIC_RESOLVER_QUERY_HPP