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.

stream_protocol.hpp 3.2KB

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