• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // ip/udp_ext.hpp
3 // ~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 // Copyright (C) 2016-2018 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
7 //
8 // Distributed under the Boost Software License, Version 1.0. (See accompanying
9 // file LICENSE_boost or copy at http://www.boost.org/LICENSE_1_0.txt)
10 //
11 
12 #ifndef BOOST_ASIO_IP_UDP_EXT_HPP
13 #define BOOST_ASIO_IP_UDP_EXT_HPP
14 
15 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 # pragma once
17 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 
19 #include <boost/asio/detail/config.hpp>
20 #include <boost/asio/basic_datagram_socket_ext.hpp>
21 #include <boost/asio/detail/socket_types.hpp>
22 #include <boost/asio/ip/basic_endpoint.hpp>
23 #include <boost/asio/ip/basic_resolver.hpp>
24 #include <boost/asio/ip/basic_resolver_iterator.hpp>
25 #include <boost/asio/ip/basic_resolver_query.hpp>
26 #include <boost/asio/ip/udp.hpp>
27 
28 #include <boost/asio/detail/push_options.hpp>
29 
30 namespace boost {
31 namespace asio {
32 namespace ip {
33 
34 /// Encapsulates the flags needed for UDP.
35 /**
36  * The boost::asio::ip::udp_ext class contains flags necessary for UDP sockets.
37  *
38  * @par Thread Safety
39  * @e Distinct @e objects: Safe.@n
40  * @e Shared @e objects: Safe.
41  *
42  * @par Concepts:
43  * Protocol, InternetProtocol.
44  */
45 class udp_ext
46 {
47 public:
48   /// The type of a UDP endpoint.
49   typedef basic_endpoint<udp> endpoint;
50 
51   /// Construct to represent the IPv4 UDP protocol.
v4()52   static udp_ext v4()
53   {
54     return udp_ext(BOOST_ASIO_OS_DEF(AF_INET));
55   }
56 
57   /// Construct to represent the IPv6 UDP protocol.
v6()58   static udp_ext v6()
59   {
60     return udp_ext(BOOST_ASIO_OS_DEF(AF_INET6));
61   }
62 
63   /// Obtain an identifier for the type of the protocol.
type() const64   int type() const
65   {
66     return BOOST_ASIO_OS_DEF(SOCK_DGRAM);
67   }
68 
69   /// Obtain an identifier for the protocol.
protocol() const70   int protocol() const
71   {
72     return BOOST_ASIO_OS_DEF(IPPROTO_UDP);
73   }
74 
75   /// Obtain an identifier for the protocol family.
family() const76   int family() const
77   {
78     return family_;
79   }
80 
81   /// The UDP socket type.
82   typedef basic_datagram_socket_ext<udp> socket;
83 
84   /// The UDP resolver type.
85   typedef basic_resolver<udp> resolver;
86 
87   /// Compare two protocols for equality.
operator ==(const udp_ext & p1,const udp_ext & p2)88   friend bool operator==(const udp_ext& p1, const udp_ext& p2)
89   {
90     return p1.family_ == p2.family_;
91   }
92 
93   /// Compare two protocols for inequality.
operator !=(const udp_ext & p1,const udp_ext & p2)94   friend bool operator!=(const udp_ext& p1, const udp_ext& p2)
95   {
96     return p1.family_ != p2.family_;
97   }
98 
99 private:
100   // Construct with a specific family.
udp_ext(int protocol_family)101   explicit udp_ext(int protocol_family)
102     : family_(protocol_family)
103   {
104   }
105 
106   int family_;
107 };
108 
109 } // namespace ip
110 } // namespace asio
111 } // namespace boost
112 
113 #include <boost/asio/detail/pop_options.hpp>
114 
115 #endif // BOOST_ASIO_IP_UDP_EXT_HPP
116