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.

122 lines
3.0KB

  1. //
  2. // generic/raw_protocol.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_RAW_PROTOCOL_HPP
  11. #define ASIO_GENERIC_RAW_PROTOCOL_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 <typeinfo>
  17. #include "asio/basic_raw_socket.hpp"
  18. #include "asio/detail/socket_types.hpp"
  19. #include "asio/detail/throw_exception.hpp"
  20. #include "asio/generic/basic_endpoint.hpp"
  21. #include "asio/detail/push_options.hpp"
  22. namespace asio {
  23. namespace generic {
  24. /// Encapsulates the flags needed for a generic raw socket.
  25. /**
  26. * The asio::generic::raw_protocol class contains flags necessary for
  27. * raw sockets of any address family and protocol.
  28. *
  29. * @par Examples
  30. * Constructing using a native address family and socket protocol:
  31. * @code raw_protocol p(AF_INET, IPPROTO_ICMP); @endcode
  32. * Constructing from a specific protocol type:
  33. * @code raw_protocol p(asio::ip::icmp::v4()); @endcode
  34. *
  35. * @par Thread Safety
  36. * @e Distinct @e objects: Safe.@n
  37. * @e Shared @e objects: Safe.
  38. *
  39. * @par Concepts:
  40. * Protocol.
  41. */
  42. class raw_protocol
  43. {
  44. public:
  45. /// Construct a protocol object for a specific address family and protocol.
  46. raw_protocol(int address_family, int socket_protocol)
  47. : family_(address_family),
  48. protocol_(socket_protocol)
  49. {
  50. }
  51. /// Construct a generic protocol object from a specific protocol.
  52. /**
  53. * @throws @c bad_cast Thrown if the source protocol is not raw-oriented.
  54. */
  55. template <typename Protocol>
  56. raw_protocol(const Protocol& source_protocol)
  57. : family_(source_protocol.family()),
  58. protocol_(source_protocol.protocol())
  59. {
  60. if (source_protocol.type() != type())
  61. {
  62. std::bad_cast ex;
  63. asio::detail::throw_exception(ex);
  64. }
  65. }
  66. /// Obtain an identifier for the type of the protocol.
  67. int type() const
  68. {
  69. return ASIO_OS_DEF(SOCK_RAW);
  70. }
  71. /// Obtain an identifier for the protocol.
  72. int protocol() const
  73. {
  74. return protocol_;
  75. }
  76. /// Obtain an identifier for the protocol family.
  77. int family() const
  78. {
  79. return family_;
  80. }
  81. /// Compare two protocols for equality.
  82. friend bool operator==(const raw_protocol& p1, const raw_protocol& p2)
  83. {
  84. return p1.family_ == p2.family_ && p1.protocol_ == p2.protocol_;
  85. }
  86. /// Compare two protocols for inequality.
  87. friend bool operator!=(const raw_protocol& p1, const raw_protocol& p2)
  88. {
  89. return !(p1 == p2);
  90. }
  91. /// The type of an endpoint.
  92. typedef basic_endpoint<raw_protocol> endpoint;
  93. /// The generic socket type.
  94. typedef basic_raw_socket<raw_protocol> socket;
  95. private:
  96. int family_;
  97. int protocol_;
  98. };
  99. } // namespace generic
  100. } // namespace asio
  101. #include "asio/detail/pop_options.hpp"
  102. #endif // ASIO_GENERIC_RAW_PROTOCOL_HPP