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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. //
  2. // local/detail/endpoint.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. // Derived from a public domain implementation written by Daniel Casimiro.
  7. //
  8. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  9. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  10. //
  11. #ifndef ASIO_LOCAL_DETAIL_ENDPOINT_HPP
  12. #define ASIO_LOCAL_DETAIL_ENDPOINT_HPP
  13. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  14. # pragma once
  15. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  16. #include "asio/detail/config.hpp"
  17. #if defined(ASIO_HAS_LOCAL_SOCKETS)
  18. #include <cstddef>
  19. #include <string>
  20. #include "asio/detail/socket_types.hpp"
  21. #include "asio/detail/string_view.hpp"
  22. #include "asio/detail/push_options.hpp"
  23. namespace asio {
  24. namespace local {
  25. namespace detail {
  26. // Helper class for implementing a UNIX domain endpoint.
  27. class endpoint
  28. {
  29. public:
  30. // Default constructor.
  31. ASIO_DECL endpoint();
  32. // Construct an endpoint using the specified path name.
  33. ASIO_DECL endpoint(const char* path_name);
  34. // Construct an endpoint using the specified path name.
  35. ASIO_DECL endpoint(const std::string& path_name);
  36. #if defined(ASIO_HAS_STRING_VIEW)
  37. // Construct an endpoint using the specified path name.
  38. ASIO_DECL endpoint(string_view path_name);
  39. #endif // defined(ASIO_HAS_STRING_VIEW)
  40. // Copy constructor.
  41. endpoint(const endpoint& other)
  42. : data_(other.data_),
  43. path_length_(other.path_length_)
  44. {
  45. }
  46. // Assign from another endpoint.
  47. endpoint& operator=(const endpoint& other)
  48. {
  49. data_ = other.data_;
  50. path_length_ = other.path_length_;
  51. return *this;
  52. }
  53. // Get the underlying endpoint in the native type.
  54. asio::detail::socket_addr_type* data()
  55. {
  56. return &data_.base;
  57. }
  58. // Get the underlying endpoint in the native type.
  59. const asio::detail::socket_addr_type* data() const
  60. {
  61. return &data_.base;
  62. }
  63. // Get the underlying size of the endpoint in the native type.
  64. std::size_t size() const
  65. {
  66. return path_length_
  67. + offsetof(asio::detail::sockaddr_un_type, sun_path);
  68. }
  69. // Set the underlying size of the endpoint in the native type.
  70. ASIO_DECL void resize(std::size_t size);
  71. // Get the capacity of the endpoint in the native type.
  72. std::size_t capacity() const
  73. {
  74. return sizeof(asio::detail::sockaddr_un_type);
  75. }
  76. // Get the path associated with the endpoint.
  77. ASIO_DECL std::string path() const;
  78. // Set the path associated with the endpoint.
  79. ASIO_DECL void path(const char* p);
  80. // Set the path associated with the endpoint.
  81. ASIO_DECL void path(const std::string& p);
  82. // Compare two endpoints for equality.
  83. ASIO_DECL friend bool operator==(
  84. const endpoint& e1, const endpoint& e2);
  85. // Compare endpoints for ordering.
  86. ASIO_DECL friend bool operator<(
  87. const endpoint& e1, const endpoint& e2);
  88. private:
  89. // The underlying UNIX socket address.
  90. union data_union
  91. {
  92. asio::detail::socket_addr_type base;
  93. asio::detail::sockaddr_un_type local;
  94. } data_;
  95. // The length of the path associated with the endpoint.
  96. std::size_t path_length_;
  97. // Initialise with a specified path.
  98. ASIO_DECL void init(const char* path, std::size_t path_length);
  99. };
  100. } // namespace detail
  101. } // namespace local
  102. } // namespace asio
  103. #include "asio/detail/pop_options.hpp"
  104. #if defined(ASIO_HEADER_ONLY)
  105. # include "asio/local/detail/impl/endpoint.ipp"
  106. #endif // defined(ASIO_HEADER_ONLY)
  107. #endif // defined(ASIO_HAS_LOCAL_SOCKETS)
  108. #endif // ASIO_LOCAL_DETAIL_ENDPOINT_HPP