Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:33:34

0001 //
0002 // ip/udp.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_UDP_HPP
0012 #define BOOST_ASIO_IP_UDP_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_datagram_socket.hpp>
0020 #include <boost/asio/detail/socket_types.hpp>
0021 #include <boost/asio/ip/basic_endpoint.hpp>
0022 #include <boost/asio/ip/basic_resolver.hpp>
0023 #include <boost/asio/ip/basic_resolver_iterator.hpp>
0024 #include <boost/asio/ip/basic_resolver_query.hpp>
0025 
0026 #include <boost/asio/detail/push_options.hpp>
0027 
0028 namespace boost {
0029 namespace asio {
0030 namespace ip {
0031 
0032 /// Encapsulates the flags needed for UDP.
0033 /**
0034  * The boost::asio::ip::udp class contains flags necessary for UDP sockets.
0035  *
0036  * @par Thread Safety
0037  * @e Distinct @e objects: Safe.@n
0038  * @e Shared @e objects: Safe.
0039  *
0040  * @par Concepts:
0041  * Protocol, InternetProtocol.
0042  */
0043 class udp
0044 {
0045 public:
0046   /// The type of a UDP endpoint.
0047   typedef basic_endpoint<udp> endpoint;
0048 
0049   /// Construct to represent the IPv4 UDP protocol.
0050   static udp v4() noexcept
0051   {
0052     return udp(BOOST_ASIO_OS_DEF(AF_INET));
0053   }
0054 
0055   /// Construct to represent the IPv6 UDP protocol.
0056   static udp v6() noexcept
0057   {
0058     return udp(BOOST_ASIO_OS_DEF(AF_INET6));
0059   }
0060 
0061   /// Obtain an identifier for the type of the protocol.
0062   int type() const noexcept
0063   {
0064     return BOOST_ASIO_OS_DEF(SOCK_DGRAM);
0065   }
0066 
0067   /// Obtain an identifier for the protocol.
0068   int protocol() const noexcept
0069   {
0070     return BOOST_ASIO_OS_DEF(IPPROTO_UDP);
0071   }
0072 
0073   /// Obtain an identifier for the protocol family.
0074   int family() const noexcept
0075   {
0076     return family_;
0077   }
0078 
0079   /// The UDP socket type.
0080   typedef basic_datagram_socket<udp> socket;
0081 
0082   /// The UDP resolver type.
0083   typedef basic_resolver<udp> resolver;
0084 
0085   /// Compare two protocols for equality.
0086   friend bool operator==(const udp& p1, const udp& p2)
0087   {
0088     return p1.family_ == p2.family_;
0089   }
0090 
0091   /// Compare two protocols for inequality.
0092   friend bool operator!=(const udp& p1, const udp& p2)
0093   {
0094     return p1.family_ != p2.family_;
0095   }
0096 
0097 private:
0098   // Construct with a specific family.
0099   explicit udp(int protocol_family) noexcept
0100     : family_(protocol_family)
0101   {
0102   }
0103 
0104   int family_;
0105 };
0106 
0107 } // namespace ip
0108 } // namespace asio
0109 } // namespace boost
0110 
0111 #include <boost/asio/detail/pop_options.hpp>
0112 
0113 #endif // BOOST_ASIO_IP_UDP_HPP