PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/dependencies/boost_1_42_0/boost/asio/ip/tcp.hpp

https://code.google.com/p/dreamofgame/
C++ Header | 162 lines | 76 code | 25 blank | 61 comment | 3 complexity | b181c5a671c8a837db1b717cd23e6a5f MD5 | raw file
  1. //
  2. // tcp.hpp
  3. // ~~~~~~~
  4. //
  5. // Copyright (c) 2003-2010 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 BOOST_ASIO_IP_TCP_HPP
  11. #define BOOST_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 <boost/asio/detail/push_options.hpp>
  16. #include <boost/asio/basic_socket_acceptor.hpp>
  17. #include <boost/asio/basic_socket_iostream.hpp>
  18. #include <boost/asio/basic_stream_socket.hpp>
  19. #include <boost/asio/ip/basic_endpoint.hpp>
  20. #include <boost/asio/ip/basic_resolver.hpp>
  21. #include <boost/asio/ip/basic_resolver_iterator.hpp>
  22. #include <boost/asio/ip/basic_resolver_query.hpp>
  23. #include <boost/asio/detail/socket_option.hpp>
  24. #include <boost/asio/detail/socket_types.hpp>
  25. namespace boost {
  26. namespace asio {
  27. namespace ip {
  28. /// Encapsulates the flags needed for TCP.
  29. /**
  30. * The boost::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. /// The type of a resolver query.
  45. typedef basic_resolver_query<tcp> resolver_query;
  46. /// The type of a resolver iterator.
  47. typedef basic_resolver_iterator<tcp> resolver_iterator;
  48. /// Construct to represent the IPv4 TCP protocol.
  49. static tcp v4()
  50. {
  51. return tcp(PF_INET);
  52. }
  53. /// Construct to represent the IPv6 TCP protocol.
  54. static tcp v6()
  55. {
  56. return tcp(PF_INET6);
  57. }
  58. /// Obtain an identifier for the type of the protocol.
  59. int type() const
  60. {
  61. return SOCK_STREAM;
  62. }
  63. /// Obtain an identifier for the protocol.
  64. int protocol() const
  65. {
  66. return IPPROTO_TCP;
  67. }
  68. /// Obtain an identifier for the protocol family.
  69. int family() const
  70. {
  71. return family_;
  72. }
  73. /// The TCP socket type.
  74. typedef basic_stream_socket<tcp> socket;
  75. /// The TCP acceptor type.
  76. typedef basic_socket_acceptor<tcp> acceptor;
  77. /// The TCP resolver type.
  78. typedef basic_resolver<tcp> resolver;
  79. #if !defined(BOOST_NO_IOSTREAM)
  80. /// The TCP iostream type.
  81. typedef basic_socket_iostream<tcp> iostream;
  82. #endif // !defined(BOOST_NO_IOSTREAM)
  83. /// Socket option for disabling the Nagle algorithm.
  84. /**
  85. * Implements the IPPROTO_TCP/TCP_NODELAY socket option.
  86. *
  87. * @par Examples
  88. * Setting the option:
  89. * @code
  90. * boost::asio::ip::tcp::socket socket(io_service);
  91. * ...
  92. * boost::asio::ip::tcp::no_delay option(true);
  93. * socket.set_option(option);
  94. * @endcode
  95. *
  96. * @par
  97. * Getting the current option value:
  98. * @code
  99. * boost::asio::ip::tcp::socket socket(io_service);
  100. * ...
  101. * boost::asio::ip::tcp::no_delay option;
  102. * socket.get_option(option);
  103. * bool is_set = option.value();
  104. * @endcode
  105. *
  106. * @par Concepts:
  107. * Socket_Option, Boolean_Socket_Option.
  108. */
  109. #if defined(GENERATING_DOCUMENTATION)
  110. typedef implementation_defined no_delay;
  111. #else
  112. typedef boost::asio::detail::socket_option::boolean<
  113. IPPROTO_TCP, TCP_NODELAY> no_delay;
  114. #endif
  115. /// Compare two protocols for equality.
  116. friend bool operator==(const tcp& p1, const tcp& p2)
  117. {
  118. return p1.family_ == p2.family_;
  119. }
  120. /// Compare two protocols for inequality.
  121. friend bool operator!=(const tcp& p1, const tcp& p2)
  122. {
  123. return p1.family_ != p2.family_;
  124. }
  125. private:
  126. // Construct with a specific family.
  127. explicit tcp(int family)
  128. : family_(family)
  129. {
  130. }
  131. int family_;
  132. };
  133. } // namespace ip
  134. } // namespace asio
  135. } // namespace boost
  136. #include <boost/asio/detail/pop_options.hpp>
  137. #endif // BOOST_ASIO_IP_TCP_HPP