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.

endpoint.hpp 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //
  2. // ip/detail/endpoint.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_DETAIL_ENDPOINT_HPP
  11. #define ASIO_IP_DETAIL_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 <string>
  17. #include "asio/detail/socket_types.hpp"
  18. #include "asio/detail/winsock_init.hpp"
  19. #include "asio/error_code.hpp"
  20. #include "asio/ip/address.hpp"
  21. #include "asio/detail/push_options.hpp"
  22. namespace asio {
  23. namespace ip {
  24. namespace detail {
  25. // Helper class for implementating an IP endpoint.
  26. class endpoint
  27. {
  28. public:
  29. // Default constructor.
  30. ASIO_DECL endpoint() ASIO_NOEXCEPT;
  31. // Construct an endpoint using a family and port number.
  32. ASIO_DECL endpoint(int family,
  33. unsigned short port_num) ASIO_NOEXCEPT;
  34. // Construct an endpoint using an address and port number.
  35. ASIO_DECL endpoint(const asio::ip::address& addr,
  36. unsigned short port_num) ASIO_NOEXCEPT;
  37. // Copy constructor.
  38. endpoint(const endpoint& other) ASIO_NOEXCEPT
  39. : data_(other.data_)
  40. {
  41. }
  42. // Assign from another endpoint.
  43. endpoint& operator=(const endpoint& other) ASIO_NOEXCEPT
  44. {
  45. data_ = other.data_;
  46. return *this;
  47. }
  48. // Get the underlying endpoint in the native type.
  49. asio::detail::socket_addr_type* data() ASIO_NOEXCEPT
  50. {
  51. return &data_.base;
  52. }
  53. // Get the underlying endpoint in the native type.
  54. const asio::detail::socket_addr_type* data() const ASIO_NOEXCEPT
  55. {
  56. return &data_.base;
  57. }
  58. // Get the underlying size of the endpoint in the native type.
  59. std::size_t size() const ASIO_NOEXCEPT
  60. {
  61. if (is_v4())
  62. return sizeof(asio::detail::sockaddr_in4_type);
  63. else
  64. return sizeof(asio::detail::sockaddr_in6_type);
  65. }
  66. // Set the underlying size of the endpoint in the native type.
  67. ASIO_DECL void resize(std::size_t new_size);
  68. // Get the capacity of the endpoint in the native type.
  69. std::size_t capacity() const ASIO_NOEXCEPT
  70. {
  71. return sizeof(data_);
  72. }
  73. // Get the port associated with the endpoint.
  74. ASIO_DECL unsigned short port() const ASIO_NOEXCEPT;
  75. // Set the port associated with the endpoint.
  76. ASIO_DECL void port(unsigned short port_num) ASIO_NOEXCEPT;
  77. // Get the IP address associated with the endpoint.
  78. ASIO_DECL asio::ip::address address() const ASIO_NOEXCEPT;
  79. // Set the IP address associated with the endpoint.
  80. ASIO_DECL void address(
  81. const asio::ip::address& addr) ASIO_NOEXCEPT;
  82. // Compare two endpoints for equality.
  83. ASIO_DECL friend bool operator==(const endpoint& e1,
  84. const endpoint& e2) ASIO_NOEXCEPT;
  85. // Compare endpoints for ordering.
  86. ASIO_DECL friend bool operator<(const endpoint& e1,
  87. const endpoint& e2) ASIO_NOEXCEPT;
  88. // Determine whether the endpoint is IPv4.
  89. bool is_v4() const ASIO_NOEXCEPT
  90. {
  91. return data_.base.sa_family == ASIO_OS_DEF(AF_INET);
  92. }
  93. #if !defined(ASIO_NO_IOSTREAM)
  94. // Convert to a string.
  95. ASIO_DECL std::string to_string() const;
  96. #endif // !defined(ASIO_NO_IOSTREAM)
  97. private:
  98. // The underlying IP socket address.
  99. union data_union
  100. {
  101. asio::detail::socket_addr_type base;
  102. asio::detail::sockaddr_in4_type v4;
  103. asio::detail::sockaddr_in6_type v6;
  104. } data_;
  105. };
  106. } // namespace detail
  107. } // namespace ip
  108. } // namespace asio
  109. #include "asio/detail/pop_options.hpp"
  110. #if defined(ASIO_HEADER_ONLY)
  111. # include "asio/ip/detail/impl/endpoint.ipp"
  112. #endif // defined(ASIO_HEADER_ONLY)
  113. #endif // ASIO_IP_DETAIL_ENDPOINT_HPP