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.

basic_endpoint.hpp 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. //
  2. // ip/basic_endpoint.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 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_ENDPOINT_HPP
  11. #define ASIO_IP_BASIC_ENDPOINT_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 "asio/ip/address.hpp"
  17. #include "asio/ip/detail/endpoint.hpp"
  18. #if !defined(ASIO_NO_IOSTREAM)
  19. # include <iosfwd>
  20. #endif // !defined(ASIO_NO_IOSTREAM)
  21. #include "asio/detail/push_options.hpp"
  22. namespace asio {
  23. namespace ip {
  24. /// Describes an endpoint for a version-independent IP socket.
  25. /**
  26. * The asio::ip::basic_endpoint class template describes an endpoint that
  27. * may be associated with a particular socket.
  28. *
  29. * @par Thread Safety
  30. * @e Distinct @e objects: Safe.@n
  31. * @e Shared @e objects: Unsafe.
  32. *
  33. * @par Concepts:
  34. * Endpoint.
  35. */
  36. template <typename InternetProtocol>
  37. class basic_endpoint
  38. {
  39. public:
  40. /// The protocol type associated with the endpoint.
  41. typedef InternetProtocol protocol_type;
  42. /// The type of the endpoint structure. This type is dependent on the
  43. /// underlying implementation of the socket layer.
  44. #if defined(GENERATING_DOCUMENTATION)
  45. typedef implementation_defined data_type;
  46. #else
  47. typedef asio::detail::socket_addr_type data_type;
  48. #endif
  49. /// Default constructor.
  50. basic_endpoint()
  51. : impl_()
  52. {
  53. }
  54. /// Construct an endpoint using a port number, specified in the host's byte
  55. /// order. The IP address will be the any address (i.e. INADDR_ANY or
  56. /// in6addr_any). This constructor would typically be used for accepting new
  57. /// connections.
  58. /**
  59. * @par Examples
  60. * To initialise an IPv4 TCP endpoint for port 1234, use:
  61. * @code
  62. * asio::ip::tcp::endpoint ep(asio::ip::tcp::v4(), 1234);
  63. * @endcode
  64. *
  65. * To specify an IPv6 UDP endpoint for port 9876, use:
  66. * @code
  67. * asio::ip::udp::endpoint ep(asio::ip::udp::v6(), 9876);
  68. * @endcode
  69. */
  70. basic_endpoint(const InternetProtocol& internet_protocol,
  71. unsigned short port_num)
  72. : impl_(internet_protocol.family(), port_num)
  73. {
  74. }
  75. /// Construct an endpoint using a port number and an IP address. This
  76. /// constructor may be used for accepting connections on a specific interface
  77. /// or for making a connection to a remote endpoint.
  78. basic_endpoint(const asio::ip::address& addr, unsigned short port_num)
  79. : impl_(addr, port_num)
  80. {
  81. }
  82. /// Copy constructor.
  83. basic_endpoint(const basic_endpoint& other)
  84. : impl_(other.impl_)
  85. {
  86. }
  87. #if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
  88. /// Move constructor.
  89. basic_endpoint(basic_endpoint&& other)
  90. : impl_(other.impl_)
  91. {
  92. }
  93. #endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
  94. /// Assign from another endpoint.
  95. basic_endpoint& operator=(const basic_endpoint& other)
  96. {
  97. impl_ = other.impl_;
  98. return *this;
  99. }
  100. #if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
  101. /// Move-assign from another endpoint.
  102. basic_endpoint& operator=(basic_endpoint&& other)
  103. {
  104. impl_ = other.impl_;
  105. return *this;
  106. }
  107. #endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
  108. /// The protocol associated with the endpoint.
  109. protocol_type protocol() const
  110. {
  111. if (impl_.is_v4())
  112. return InternetProtocol::v4();
  113. return InternetProtocol::v6();
  114. }
  115. /// Get the underlying endpoint in the native type.
  116. data_type* data()
  117. {
  118. return impl_.data();
  119. }
  120. /// Get the underlying endpoint in the native type.
  121. const data_type* data() const
  122. {
  123. return impl_.data();
  124. }
  125. /// Get the underlying size of the endpoint in the native type.
  126. std::size_t size() const
  127. {
  128. return impl_.size();
  129. }
  130. /// Set the underlying size of the endpoint in the native type.
  131. void resize(std::size_t new_size)
  132. {
  133. impl_.resize(new_size);
  134. }
  135. /// Get the capacity of the endpoint in the native type.
  136. std::size_t capacity() const
  137. {
  138. return impl_.capacity();
  139. }
  140. /// Get the port associated with the endpoint. The port number is always in
  141. /// the host's byte order.
  142. unsigned short port() const
  143. {
  144. return impl_.port();
  145. }
  146. /// Set the port associated with the endpoint. The port number is always in
  147. /// the host's byte order.
  148. void port(unsigned short port_num)
  149. {
  150. impl_.port(port_num);
  151. }
  152. /// Get the IP address associated with the endpoint.
  153. asio::ip::address address() const
  154. {
  155. return impl_.address();
  156. }
  157. /// Set the IP address associated with the endpoint.
  158. void address(const asio::ip::address& addr)
  159. {
  160. impl_.address(addr);
  161. }
  162. /// Compare two endpoints for equality.
  163. friend bool operator==(const basic_endpoint<InternetProtocol>& e1,
  164. const basic_endpoint<InternetProtocol>& e2)
  165. {
  166. return e1.impl_ == e2.impl_;
  167. }
  168. /// Compare two endpoints for inequality.
  169. friend bool operator!=(const basic_endpoint<InternetProtocol>& e1,
  170. const basic_endpoint<InternetProtocol>& e2)
  171. {
  172. return !(e1 == e2);
  173. }
  174. /// Compare endpoints for ordering.
  175. friend bool operator<(const basic_endpoint<InternetProtocol>& e1,
  176. const basic_endpoint<InternetProtocol>& e2)
  177. {
  178. return e1.impl_ < e2.impl_;
  179. }
  180. /// Compare endpoints for ordering.
  181. friend bool operator>(const basic_endpoint<InternetProtocol>& e1,
  182. const basic_endpoint<InternetProtocol>& e2)
  183. {
  184. return e2.impl_ < e1.impl_;
  185. }
  186. /// Compare endpoints for ordering.
  187. friend bool operator<=(const basic_endpoint<InternetProtocol>& e1,
  188. const basic_endpoint<InternetProtocol>& e2)
  189. {
  190. return !(e2 < e1);
  191. }
  192. /// Compare endpoints for ordering.
  193. friend bool operator>=(const basic_endpoint<InternetProtocol>& e1,
  194. const basic_endpoint<InternetProtocol>& e2)
  195. {
  196. return !(e1 < e2);
  197. }
  198. private:
  199. // The underlying IP endpoint.
  200. asio::ip::detail::endpoint impl_;
  201. };
  202. #if !defined(ASIO_NO_IOSTREAM)
  203. /// Output an endpoint as a string.
  204. /**
  205. * Used to output a human-readable string for a specified endpoint.
  206. *
  207. * @param os The output stream to which the string will be written.
  208. *
  209. * @param endpoint The endpoint to be written.
  210. *
  211. * @return The output stream.
  212. *
  213. * @relates asio::ip::basic_endpoint
  214. */
  215. template <typename Elem, typename Traits, typename InternetProtocol>
  216. std::basic_ostream<Elem, Traits>& operator<<(
  217. std::basic_ostream<Elem, Traits>& os,
  218. const basic_endpoint<InternetProtocol>& endpoint);
  219. #endif // !defined(ASIO_NO_IOSTREAM)
  220. } // namespace ip
  221. } // namespace asio
  222. #include "asio/detail/pop_options.hpp"
  223. #include "asio/ip/impl/basic_endpoint.hpp"
  224. #endif // ASIO_IP_BASIC_ENDPOINT_HPP