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.

seq_packet_protocol.hpp 3.0KB

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