Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:00

0001 //
0002 // ip/tcp.hpp
0003 // ~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_IP_TCP_HPP
0012 #define BOOST_ASIO_IP_TCP_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 #include <boost/asio/basic_socket_acceptor.hpp>
0020 #include <boost/asio/basic_socket_iostream.hpp>
0021 #include <boost/asio/basic_stream_socket.hpp>
0022 #include <boost/asio/detail/socket_option.hpp>
0023 #include <boost/asio/detail/socket_types.hpp>
0024 #include <boost/asio/ip/basic_endpoint.hpp>
0025 #include <boost/asio/ip/basic_resolver.hpp>
0026 #include <boost/asio/ip/basic_resolver_iterator.hpp>
0027 #include <boost/asio/ip/basic_resolver_query.hpp>
0028 
0029 #include <boost/asio/detail/push_options.hpp>
0030 
0031 namespace boost {
0032 namespace asio {
0033 namespace ip {
0034 
0035 /// Encapsulates the flags needed for TCP.
0036 /**
0037  * The boost::asio::ip::tcp class contains flags necessary for TCP sockets.
0038  *
0039  * @par Thread Safety
0040  * @e Distinct @e objects: Safe.@n
0041  * @e Shared @e objects: Safe.
0042  *
0043  * @par Concepts:
0044  * Protocol, InternetProtocol.
0045  */
0046 class tcp
0047 {
0048 public:
0049   /// The type of a TCP endpoint.
0050   typedef basic_endpoint<tcp> endpoint;
0051 
0052   /// Construct to represent the IPv4 TCP protocol.
0053   static tcp v4() noexcept
0054   {
0055     return tcp(BOOST_ASIO_OS_DEF(AF_INET));
0056   }
0057 
0058   /// Construct to represent the IPv6 TCP protocol.
0059   static tcp v6() noexcept
0060   {
0061     return tcp(BOOST_ASIO_OS_DEF(AF_INET6));
0062   }
0063 
0064   /// Obtain an identifier for the type of the protocol.
0065   int type() const noexcept
0066   {
0067     return BOOST_ASIO_OS_DEF(SOCK_STREAM);
0068   }
0069 
0070   /// Obtain an identifier for the protocol.
0071   int protocol() const noexcept
0072   {
0073     return BOOST_ASIO_OS_DEF(IPPROTO_TCP);
0074   }
0075 
0076   /// Obtain an identifier for the protocol family.
0077   int family() const noexcept
0078   {
0079     return family_;
0080   }
0081 
0082   /// The TCP socket type.
0083   typedef basic_stream_socket<tcp> socket;
0084 
0085   /// The TCP acceptor type.
0086   typedef basic_socket_acceptor<tcp> acceptor;
0087 
0088   /// The TCP resolver type.
0089   typedef basic_resolver<tcp> resolver;
0090 
0091 #if !defined(BOOST_ASIO_NO_IOSTREAM)
0092   /// The TCP iostream type.
0093   typedef basic_socket_iostream<tcp> iostream;
0094 #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
0095 
0096   /// Socket option for disabling the Nagle algorithm.
0097   /**
0098    * Implements the IPPROTO_TCP/TCP_NODELAY socket option.
0099    *
0100    * @par Examples
0101    * Setting the option:
0102    * @code
0103    * boost::asio::ip::tcp::socket socket(my_context);
0104    * ...
0105    * boost::asio::ip::tcp::no_delay option(true);
0106    * socket.set_option(option);
0107    * @endcode
0108    *
0109    * @par
0110    * Getting the current option value:
0111    * @code
0112    * boost::asio::ip::tcp::socket socket(my_context);
0113    * ...
0114    * boost::asio::ip::tcp::no_delay option;
0115    * socket.get_option(option);
0116    * bool is_set = option.value();
0117    * @endcode
0118    *
0119    * @par Concepts:
0120    * Socket_Option, Boolean_Socket_Option.
0121    */
0122 #if defined(GENERATING_DOCUMENTATION)
0123   typedef implementation_defined no_delay;
0124 #else
0125   typedef boost::asio::detail::socket_option::boolean<
0126     BOOST_ASIO_OS_DEF(IPPROTO_TCP), BOOST_ASIO_OS_DEF(TCP_NODELAY)> no_delay;
0127 #endif
0128 
0129   /// Compare two protocols for equality.
0130   friend bool operator==(const tcp& p1, const tcp& p2)
0131   {
0132     return p1.family_ == p2.family_;
0133   }
0134 
0135   /// Compare two protocols for inequality.
0136   friend bool operator!=(const tcp& p1, const tcp& p2)
0137   {
0138     return p1.family_ != p2.family_;
0139   }
0140 
0141 private:
0142   // Construct with a specific family.
0143   explicit tcp(int protocol_family) noexcept
0144     : family_(protocol_family)
0145   {
0146   }
0147 
0148   int family_;
0149 };
0150 
0151 } // namespace ip
0152 } // namespace asio
0153 } // namespace boost
0154 
0155 #include <boost/asio/detail/pop_options.hpp>
0156 
0157 #endif // BOOST_ASIO_IP_TCP_HPP