5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef BOOST_ASIO_IP_TCP_HPP
12 #define BOOST_ASIO_IP_TCP_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
19 #include <boost/asio/basic_socket_acceptor.hpp>
20 #include <boost/asio/basic_socket_iostream.hpp>
21 #include <boost/asio/basic_stream_socket.hpp>
22 #include <boost/asio/detail/socket_option.hpp>
23 #include <boost/asio/detail/socket_types.hpp>
24 #include <boost/asio/ip/basic_endpoint.hpp>
25 #include <boost/asio/ip/basic_resolver.hpp>
26 #include <boost/asio/ip/basic_resolver_iterator.hpp>
27 #include <boost/asio/ip/basic_resolver_query.hpp>
29 #include <boost/asio/detail/push_options.hpp>
35 /// Encapsulates the flags needed for TCP.
37 * The boost::asio::ip::tcp class contains flags necessary for TCP sockets.
40 * @e Distinct @e objects: Safe.@n
41 * @e Shared @e objects: Safe.
44 * Protocol, InternetProtocol.
49 /// The type of a TCP endpoint.
50 typedef basic_endpoint<tcp> endpoint;
52 /// Construct to represent the IPv4 TCP protocol.
55 return tcp(BOOST_ASIO_OS_DEF(AF_INET));
58 /// Construct to represent the IPv6 TCP protocol.
61 return tcp(BOOST_ASIO_OS_DEF(AF_INET6));
64 /// Obtain an identifier for the type of the protocol.
67 return BOOST_ASIO_OS_DEF(SOCK_STREAM);
70 /// Obtain an identifier for the protocol.
73 return BOOST_ASIO_OS_DEF(IPPROTO_TCP);
76 /// Obtain an identifier for the protocol family.
82 /// The TCP socket type.
83 typedef basic_stream_socket<tcp> socket;
85 /// The TCP acceptor type.
86 typedef basic_socket_acceptor<tcp> acceptor;
88 /// The TCP resolver type.
89 typedef basic_resolver<tcp> resolver;
91 #if !defined(BOOST_ASIO_NO_IOSTREAM)
92 /// The TCP iostream type.
93 typedef basic_socket_iostream<tcp> iostream;
94 #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
96 /// Socket option for disabling the Nagle algorithm.
98 * Implements the IPPROTO_TCP/TCP_NODELAY socket option.
101 * Setting the option:
103 * boost::asio::ip::tcp::socket socket(io_context);
105 * boost::asio::ip::tcp::no_delay option(true);
106 * socket.set_option(option);
110 * Getting the current option value:
112 * boost::asio::ip::tcp::socket socket(io_context);
114 * boost::asio::ip::tcp::no_delay option;
115 * socket.get_option(option);
116 * bool is_set = option.value();
120 * Socket_Option, Boolean_Socket_Option.
122 #if defined(GENERATING_DOCUMENTATION)
123 typedef implementation_defined no_delay;
125 typedef boost::asio::detail::socket_option::boolean<
126 BOOST_ASIO_OS_DEF(IPPROTO_TCP), BOOST_ASIO_OS_DEF(TCP_NODELAY)> no_delay;
129 /// Compare two protocols for equality.
130 friend bool operator==(const tcp& p1, const tcp& p2)
132 return p1.family_ == p2.family_;
135 /// Compare two protocols for inequality.
136 friend bool operator!=(const tcp& p1, const tcp& p2)
138 return p1.family_ != p2.family_;
142 // Construct with a specific family.
143 explicit tcp(int protocol_family)
144 : family_(protocol_family)
155 #include <boost/asio/detail/pop_options.hpp>
157 #endif // BOOST_ASIO_IP_TCP_HPP