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.4KB

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