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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //
  2. // local/detail/endpoint.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 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/push_options.hpp"
  22. namespace asio {
  23. namespace local {
  24. namespace detail {
  25. // Helper class for implementing a UNIX domain endpoint.
  26. class endpoint
  27. {
  28. public:
  29. // Default constructor.
  30. ASIO_DECL endpoint();
  31. // Construct an endpoint using the specified path name.
  32. ASIO_DECL endpoint(const char* path_name);
  33. // Construct an endpoint using the specified path name.
  34. ASIO_DECL endpoint(const std::string& path_name);
  35. // Copy constructor.
  36. endpoint(const endpoint& other)
  37. : data_(other.data_),
  38. path_length_(other.path_length_)
  39. {
  40. }
  41. // Assign from another endpoint.
  42. endpoint& operator=(const endpoint& other)
  43. {
  44. data_ = other.data_;
  45. path_length_ = other.path_length_;
  46. return *this;
  47. }
  48. // Get the underlying endpoint in the native type.
  49. asio::detail::socket_addr_type* data()
  50. {
  51. return &data_.base;
  52. }
  53. // Get the underlying endpoint in the native type.
  54. const asio::detail::socket_addr_type* data() const
  55. {
  56. return &data_.base;
  57. }
  58. // Get the underlying size of the endpoint in the native type.
  59. std::size_t size() const
  60. {
  61. return path_length_
  62. + offsetof(asio::detail::sockaddr_un_type, sun_path);
  63. }
  64. // Set the underlying size of the endpoint in the native type.
  65. ASIO_DECL void resize(std::size_t size);
  66. // Get the capacity of the endpoint in the native type.
  67. std::size_t capacity() const
  68. {
  69. return sizeof(asio::detail::sockaddr_un_type);
  70. }
  71. // Get the path associated with the endpoint.
  72. ASIO_DECL std::string path() const;
  73. // Set the path associated with the endpoint.
  74. ASIO_DECL void path(const char* p);
  75. // Set the path associated with the endpoint.
  76. ASIO_DECL void path(const std::string& p);
  77. // Compare two endpoints for equality.
  78. ASIO_DECL friend bool operator==(
  79. const endpoint& e1, const endpoint& e2);
  80. // Compare endpoints for ordering.
  81. ASIO_DECL friend bool operator<(
  82. const endpoint& e1, const endpoint& e2);
  83. private:
  84. // The underlying UNIX socket address.
  85. union data_union
  86. {
  87. asio::detail::socket_addr_type base;
  88. asio::detail::sockaddr_un_type local;
  89. } data_;
  90. // The length of the path associated with the endpoint.
  91. std::size_t path_length_;
  92. // Initialise with a specified path.
  93. ASIO_DECL void init(const char* path, std::size_t path_length);
  94. };
  95. } // namespace detail
  96. } // namespace local
  97. } // namespace asio
  98. #include "asio/detail/pop_options.hpp"
  99. #if defined(ASIO_HEADER_ONLY)
  100. # include "asio/local/detail/impl/endpoint.ipp"
  101. #endif // defined(ASIO_HEADER_ONLY)
  102. #endif // defined(ASIO_HAS_LOCAL_SOCKETS)
  103. #endif // ASIO_LOCAL_DETAIL_ENDPOINT_HPP