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
11#ifndef BOOST_ASIO_IP_TCP_HPP
12#define BOOST_ASIO_IP_TCP_HPP
13
14#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15# pragma once
16#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
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>
28
29#include <boost/asio/detail/push_options.hpp>
30
31namespace boost {
32namespace asio {
33namespace ip {
34
35/// Encapsulates the flags needed for TCP.
36/**
37 * The boost::asio::ip::tcp class contains flags necessary for TCP sockets.
38 *
39 * @par Thread Safety
40 * @e Distinct @e objects: Safe.@n
41 * @e Shared @e objects: Safe.
42 *
43 * @par Concepts:
44 * Protocol, InternetProtocol.
45 */
46class tcp
47{
48public:
49 /// The type of a TCP endpoint.
50 typedef basic_endpoint<tcp> endpoint;
51
52 /// Construct to represent the IPv4 TCP protocol.
53 static tcp v4()
54 {
55 return tcp(BOOST_ASIO_OS_DEF(AF_INET));
56 }
57
58 /// Construct to represent the IPv6 TCP protocol.
59 static tcp v6()
60 {
61 return tcp(BOOST_ASIO_OS_DEF(AF_INET6));
62 }
63
64 /// Obtain an identifier for the type of the protocol.
65 int type() const
66 {
67 return BOOST_ASIO_OS_DEF(SOCK_STREAM);
68 }
69
70 /// Obtain an identifier for the protocol.
71 int protocol() const
72 {
73 return BOOST_ASIO_OS_DEF(IPPROTO_TCP);
74 }
75
76 /// Obtain an identifier for the protocol family.
77 int family() const
78 {
79 return family_;
80 }
81
82 /// The TCP socket type.
83 typedef basic_stream_socket<tcp> socket;
84
85 /// The TCP acceptor type.
86 typedef basic_socket_acceptor<tcp> acceptor;
87
88 /// The TCP resolver type.
89 typedef basic_resolver<tcp> resolver;
90
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)
95
96 /// Socket option for disabling the Nagle algorithm.
97 /**
98 * Implements the IPPROTO_TCP/TCP_NODELAY socket option.
99 *
100 * @par Examples
101 * Setting the option:
102 * @code
103 * boost::asio::ip::tcp::socket socket(io_service);
104 * ...
105 * boost::asio::ip::tcp::no_delay option(true);
106 * socket.set_option(option);
107 * @endcode
108 *
109 * @par
110 * Getting the current option value:
111 * @code
112 * boost::asio::ip::tcp::socket socket(io_service);
113 * ...
114 * boost::asio::ip::tcp::no_delay option;
115 * socket.get_option(option);
116 * bool is_set = option.value();
117 * @endcode
118 *
119 * @par Concepts:
120 * Socket_Option, Boolean_Socket_Option.
121 */
122#if defined(GENERATING_DOCUMENTATION)
123 typedef implementation_defined no_delay;
124#else
125 typedef boost::asio::detail::socket_option::boolean<
126 BOOST_ASIO_OS_DEF(IPPROTO_TCP), BOOST_ASIO_OS_DEF(TCP_NODELAY)> no_delay;
127#endif
128
129 /// Compare two protocols for equality.
130 friend bool operator==(const tcp& p1, const tcp& p2)
131 {
132 return p1.family_ == p2.family_;
133 }
134
135 /// Compare two protocols for inequality.
136 friend bool operator!=(const tcp& p1, const tcp& p2)
137 {
138 return p1.family_ != p2.family_;
139 }
140
141private:
142 // Construct with a specific family.
143 explicit tcp(int protocol_family)
144 : family_(protocol_family)
145 {
146 }
147
148 int family_;
149};
150
151} // namespace ip
152} // namespace asio
153} // namespace boost
154
155#include <boost/asio/detail/pop_options.hpp>
156
157#endif // BOOST_ASIO_IP_TCP_HPP
158

source code of boost/boost/asio/ip/tcp.hpp