10ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// 20ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// ip/tcp.hpp 30ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// ~~~~~~~~~~ 40ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// 50ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) 60ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// 70ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// Distributed under the Boost Software License, Version 1.0. (See accompanying 80ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 90ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// 100ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie 110ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#ifndef ASIO_IP_TCP_HPP 120ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#define ASIO_IP_TCP_HPP 130ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie 140ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie 150ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/detail/config.hpp" 160ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/basic_socket_acceptor.hpp" 170ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/basic_socket_iostream.hpp" 180ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/basic_stream_socket.hpp" 190ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/detail/socket_option.hpp" 200ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/detail/socket_types.hpp" 210ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/ip/basic_endpoint.hpp" 220ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/ip/basic_resolver.hpp" 230ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/ip/basic_resolver_iterator.hpp" 240ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/ip/basic_resolver_query.hpp" 250ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie 260ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/detail/push_options.hpp" 270ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie 280ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffienamespace asio { 290ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffienamespace ip { 300ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie 310ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie/// Encapsulates the flags needed for TCP. 320ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie/** 330ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * The asio::ip::tcp class contains flags necessary for TCP sockets. 340ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * 350ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * @par Thread Safety 360ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * @e Distinct @e objects: Safe.@n 370ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * @e Shared @e objects: Safe. 380ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * 390ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * @par Concepts: 400ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * Protocol, InternetProtocol. 410ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie */ 420ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieclass tcp 430ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie{ 440ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffiepublic: 450ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie /// The type of a TCP endpoint. 460ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie typedef basic_endpoint<tcp> endpoint; 470ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie 480ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie /// Construct to represent the IPv4 TCP protocol. 490ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie static tcp v4() 500ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie { 510ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie return tcp(ASIO_OS_DEF(AF_INET)); 520ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie } 530ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie 540ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie /// Construct to represent the IPv6 TCP protocol. 550ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie static tcp v6() 560ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie { 570ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie return tcp(ASIO_OS_DEF(AF_INET6)); 580ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie } 590ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie 600ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie /// Obtain an identifier for the type of the protocol. 610ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie int type() const 620ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie { 630ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie return ASIO_OS_DEF(SOCK_STREAM); 640ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie } 650ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie 660ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie /// Obtain an identifier for the protocol. 670ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie int protocol() const 680ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie { 690ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie return ASIO_OS_DEF(IPPROTO_TCP); 700ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie } 710ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie 720ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie /// Obtain an identifier for the protocol family. 730ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie int family() const 740ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie { 750ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie return family_; 760ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie } 770ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie 780ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie /// The TCP socket type. 790ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie typedef basic_stream_socket<tcp> socket; 800ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie 810ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie /// The TCP acceptor type. 820ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie typedef basic_socket_acceptor<tcp> acceptor; 830ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie 840ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie /// The TCP resolver type. 850ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie typedef basic_resolver<tcp> resolver; 860ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie 870ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie 880ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie /// Socket option for disabling the Nagle algorithm. 890ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie /** 900ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * Implements the IPPROTO_TCP/TCP_NODELAY socket option. 910ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * 920ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * @par Examples 930ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * Setting the option: 940ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * @code 950ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * asio::ip::tcp::socket socket(io_service); 960ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * ... 970ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * asio::ip::tcp::no_delay option(true); 980ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * socket.set_option(option); 990ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * @endcode 1000ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * 1010ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * @par 1020ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * Getting the current option value: 1030ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * @code 1040ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * asio::ip::tcp::socket socket(io_service); 1050ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * ... 1060ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * asio::ip::tcp::no_delay option; 1070ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * socket.get_option(option); 1080ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * bool is_set = option.value(); 1090ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * @endcode 1100ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * 1110ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * @par Concepts: 1120ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie * Socket_Option, Boolean_Socket_Option. 1130ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie */ 1140ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie typedef asio::detail::socket_option::boolean< 1150ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie ASIO_OS_DEF(IPPROTO_TCP), ASIO_OS_DEF(TCP_NODELAY)> no_delay; 1160ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie 1170ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie /// Compare two protocols for equality. 1180ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie friend bool operator==(const tcp& p1, const tcp& p2) 1190ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie { 1200ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie return p1.family_ == p2.family_; 1210ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie } 1220ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie 1230ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie /// Compare two protocols for inequality. 1240ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie friend bool operator!=(const tcp& p1, const tcp& p2) 1250ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie { 1260ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie return p1.family_ != p2.family_; 1270ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie } 1280ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie 1290ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieprivate: 1300ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie // Construct with a specific family. 1310ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie explicit tcp(int protocol_family) 1320ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie : family_(protocol_family) 1330ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie { 1340ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie } 1350ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie 1360ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie int family_; 1370ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie}; 1380ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie 1390ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie} // namespace ip 1400ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie} // namespace asio 1410ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie 1420ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/detail/pop_options.hpp" 1430ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie 1440ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#endif // ASIO_IP_TCP_HPP 145