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.

111 lines
2.6KB

  1. //
  2. // generic/detail/impl/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_GENERIC_DETAIL_IMPL_ENDPOINT_IPP
  11. #define ASIO_GENERIC_DETAIL_IMPL_ENDPOINT_IPP
  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 <cstring>
  17. #include <typeinfo>
  18. #include "asio/detail/socket_ops.hpp"
  19. #include "asio/detail/throw_error.hpp"
  20. #include "asio/detail/throw_exception.hpp"
  21. #include "asio/error.hpp"
  22. #include "asio/generic/detail/endpoint.hpp"
  23. #include "asio/detail/push_options.hpp"
  24. namespace asio {
  25. namespace generic {
  26. namespace detail {
  27. endpoint::endpoint()
  28. {
  29. init(0, 0, 0);
  30. }
  31. endpoint::endpoint(const void* sock_addr,
  32. std::size_t sock_addr_size, int sock_protocol)
  33. {
  34. init(sock_addr, sock_addr_size, sock_protocol);
  35. }
  36. void endpoint::resize(std::size_t new_size)
  37. {
  38. if (new_size > sizeof(asio::detail::sockaddr_storage_type))
  39. {
  40. asio::error_code ec(asio::error::invalid_argument);
  41. asio::detail::throw_error(ec);
  42. }
  43. else
  44. {
  45. size_ = new_size;
  46. protocol_ = 0;
  47. }
  48. }
  49. bool operator==(const endpoint& e1, const endpoint& e2)
  50. {
  51. using namespace std; // For memcmp.
  52. return e1.size() == e2.size() && memcmp(e1.data(), e2.data(), e1.size()) == 0;
  53. }
  54. bool operator<(const endpoint& e1, const endpoint& e2)
  55. {
  56. if (e1.protocol() < e2.protocol())
  57. return true;
  58. if (e1.protocol() > e2.protocol())
  59. return false;
  60. using namespace std; // For memcmp.
  61. std::size_t compare_size = e1.size() < e2.size() ? e1.size() : e2.size();
  62. int compare_result = memcmp(e1.data(), e2.data(), compare_size);
  63. if (compare_result < 0)
  64. return true;
  65. if (compare_result > 0)
  66. return false;
  67. return e1.size() < e2.size();
  68. }
  69. void endpoint::init(const void* sock_addr,
  70. std::size_t sock_addr_size, int sock_protocol)
  71. {
  72. if (sock_addr_size > sizeof(asio::detail::sockaddr_storage_type))
  73. {
  74. asio::error_code ec(asio::error::invalid_argument);
  75. asio::detail::throw_error(ec);
  76. }
  77. using namespace std; // For memset and memcpy.
  78. memset(&data_.generic, 0, sizeof(asio::detail::sockaddr_storage_type));
  79. if (sock_addr_size > 0)
  80. memcpy(&data_.generic, sock_addr, sock_addr_size);
  81. size_ = sock_addr_size;
  82. protocol_ = sock_protocol;
  83. }
  84. } // namespace detail
  85. } // namespace generic
  86. } // namespace asio
  87. #include "asio/detail/pop_options.hpp"
  88. #endif // ASIO_GENERIC_DETAIL_IMPL_ENDPOINT_IPP