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.

tcp.hpp 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //
  2. // ip/tcp.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_IP_TCP_HPP
  11. #define ASIO_IP_TCP_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 "asio/basic_socket_acceptor.hpp"
  17. #include "asio/basic_socket_iostream.hpp"
  18. #include "asio/basic_stream_socket.hpp"
  19. #include "asio/detail/socket_option.hpp"
  20. #include "asio/detail/socket_types.hpp"
  21. #include "asio/ip/basic_endpoint.hpp"
  22. #include "asio/ip/basic_resolver.hpp"
  23. #include "asio/ip/basic_resolver_iterator.hpp"
  24. #include "asio/ip/basic_resolver_query.hpp"
  25. #include "asio/detail/push_options.hpp"
  26. namespace asio {
  27. namespace ip {
  28. /// Encapsulates the flags needed for TCP.
  29. /**
  30. * The asio::ip::tcp class contains flags necessary for TCP sockets.
  31. *
  32. * @par Thread Safety
  33. * @e Distinct @e objects: Safe.@n
  34. * @e Shared @e objects: Safe.
  35. *
  36. * @par Concepts:
  37. * Protocol, InternetProtocol.
  38. */
  39. class tcp
  40. {
  41. public:
  42. /// The type of a TCP endpoint.
  43. typedef basic_endpoint<tcp> endpoint;
  44. /// Construct to represent the IPv4 TCP protocol.
  45. static tcp v4()
  46. {
  47. return tcp(ASIO_OS_DEF(AF_INET));
  48. }
  49. /// Construct to represent the IPv6 TCP protocol.
  50. static tcp v6()
  51. {
  52. return tcp(ASIO_OS_DEF(AF_INET6));
  53. }
  54. /// Obtain an identifier for the type of the protocol.
  55. int type() const
  56. {
  57. return ASIO_OS_DEF(SOCK_STREAM);
  58. }
  59. /// Obtain an identifier for the protocol.
  60. int protocol() const
  61. {
  62. return ASIO_OS_DEF(IPPROTO_TCP);
  63. }
  64. /// Obtain an identifier for the protocol family.
  65. int family() const
  66. {
  67. return family_;
  68. }
  69. /// The TCP socket type.
  70. typedef basic_stream_socket<tcp> socket;
  71. /// The TCP acceptor type.
  72. typedef basic_socket_acceptor<tcp> acceptor;
  73. /// The TCP resolver type.
  74. typedef basic_resolver<tcp> resolver;
  75. #if !defined(ASIO_NO_IOSTREAM)
  76. /// The TCP iostream type.
  77. typedef basic_socket_iostream<tcp> iostream;
  78. #endif // !defined(ASIO_NO_IOSTREAM)
  79. /// Socket option for disabling the Nagle algorithm.
  80. /**
  81. * Implements the IPPROTO_TCP/TCP_NODELAY socket option.
  82. *
  83. * @par Examples
  84. * Setting the option:
  85. * @code
  86. * asio::ip::tcp::socket socket(io_context);
  87. * ...
  88. * asio::ip::tcp::no_delay option(true);
  89. * socket.set_option(option);
  90. * @endcode
  91. *
  92. * @par
  93. * Getting the current option value:
  94. * @code
  95. * asio::ip::tcp::socket socket(io_context);
  96. * ...
  97. * asio::ip::tcp::no_delay option;
  98. * socket.get_option(option);
  99. * bool is_set = option.value();
  100. * @endcode
  101. *
  102. * @par Concepts:
  103. * Socket_Option, Boolean_Socket_Option.
  104. */
  105. #if defined(GENERATING_DOCUMENTATION)
  106. typedef implementation_defined no_delay;
  107. #else
  108. typedef asio::detail::socket_option::boolean<
  109. ASIO_OS_DEF(IPPROTO_TCP), ASIO_OS_DEF(TCP_NODELAY)> no_delay;
  110. #endif
  111. /// Compare two protocols for equality.
  112. friend bool operator==(const tcp& p1, const tcp& p2)
  113. {
  114. return p1.family_ == p2.family_;
  115. }
  116. /// Compare two protocols for inequality.
  117. friend bool operator!=(const tcp& p1, const tcp& p2)
  118. {
  119. return p1.family_ != p2.family_;
  120. }
  121. private:
  122. // Construct with a specific family.
  123. explicit tcp(int protocol_family)
  124. : family_(protocol_family)
  125. {
  126. }
  127. int family_;
  128. };
  129. } // namespace ip
  130. } // namespace asio
  131. #include "asio/detail/pop_options.hpp"
  132. #endif // ASIO_IP_TCP_HPP