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.

134 lines
3.1KB

  1. //
  2. // generic/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_GENERIC_DETAIL_ENDPOINT_HPP
  11. #define ASIO_GENERIC_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 <cstddef>
  17. #include "asio/detail/socket_types.hpp"
  18. #include "asio/detail/push_options.hpp"
  19. namespace asio {
  20. namespace generic {
  21. namespace detail {
  22. // Helper class for implementing a generic socket endpoint.
  23. class endpoint
  24. {
  25. public:
  26. // Default constructor.
  27. ASIO_DECL endpoint();
  28. // Construct an endpoint from the specified raw bytes.
  29. ASIO_DECL endpoint(const void* sock_addr,
  30. std::size_t sock_addr_size, int sock_protocol);
  31. // Copy constructor.
  32. endpoint(const endpoint& other)
  33. : data_(other.data_),
  34. size_(other.size_),
  35. protocol_(other.protocol_)
  36. {
  37. }
  38. // Assign from another endpoint.
  39. endpoint& operator=(const endpoint& other)
  40. {
  41. data_ = other.data_;
  42. size_ = other.size_;
  43. protocol_ = other.protocol_;
  44. return *this;
  45. }
  46. // Get the address family associated with the endpoint.
  47. int family() const
  48. {
  49. return data_.base.sa_family;
  50. }
  51. // Get the socket protocol associated with the endpoint.
  52. int protocol() const
  53. {
  54. return protocol_;
  55. }
  56. // Get the underlying endpoint in the native type.
  57. asio::detail::socket_addr_type* data()
  58. {
  59. return &data_.base;
  60. }
  61. // Get the underlying endpoint in the native type.
  62. const asio::detail::socket_addr_type* data() const
  63. {
  64. return &data_.base;
  65. }
  66. // Get the underlying size of the endpoint in the native type.
  67. std::size_t size() const
  68. {
  69. return size_;
  70. }
  71. // Set the underlying size of the endpoint in the native type.
  72. ASIO_DECL void resize(std::size_t size);
  73. // Get the capacity of the endpoint in the native type.
  74. std::size_t capacity() const
  75. {
  76. return sizeof(asio::detail::sockaddr_storage_type);
  77. }
  78. // Compare two endpoints for equality.
  79. ASIO_DECL friend bool operator==(
  80. const endpoint& e1, const endpoint& e2);
  81. // Compare endpoints for ordering.
  82. ASIO_DECL friend bool operator<(
  83. const endpoint& e1, const endpoint& e2);
  84. private:
  85. // The underlying socket address.
  86. union data_union
  87. {
  88. asio::detail::socket_addr_type base;
  89. asio::detail::sockaddr_storage_type generic;
  90. } data_;
  91. // The length of the socket address stored in the endpoint.
  92. std::size_t size_;
  93. // The socket protocol associated with the endpoint.
  94. int protocol_;
  95. // Initialise with a specified memory.
  96. ASIO_DECL void init(const void* sock_addr,
  97. std::size_t sock_addr_size, int sock_protocol);
  98. };
  99. } // namespace detail
  100. } // namespace generic
  101. } // namespace asio
  102. #include "asio/detail/pop_options.hpp"
  103. #if defined(ASIO_HEADER_ONLY)
  104. # include "asio/generic/detail/impl/endpoint.ipp"
  105. #endif // defined(ASIO_HEADER_ONLY)
  106. #endif // ASIO_GENERIC_DETAIL_ENDPOINT_HPP