udp.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //
  2. // ip/udp.hpp
  3. // ~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 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. #ifndef BOOST_ASIO_IP_UDP_HPP
  11. #define BOOST_ASIO_IP_UDP_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <boost/asio/basic_datagram_socket.hpp>
  17. #include <boost/asio/detail/socket_types.hpp>
  18. #include <boost/asio/ip/basic_endpoint.hpp>
  19. #include <boost/asio/ip/basic_resolver.hpp>
  20. #include <boost/asio/ip/basic_resolver_iterator.hpp>
  21. #include <boost/asio/ip/basic_resolver_query.hpp>
  22. #include <boost/asio/detail/push_options.hpp>
  23. namespace boost {
  24. namespace asio {
  25. namespace ip {
  26. /// Encapsulates the flags needed for UDP.
  27. /**
  28. * The boost::asio::ip::udp class contains flags necessary for UDP sockets.
  29. *
  30. * @par Thread Safety
  31. * @e Distinct @e objects: Safe.@n
  32. * @e Shared @e objects: Safe.
  33. *
  34. * @par Concepts:
  35. * Protocol, InternetProtocol.
  36. */
  37. class udp
  38. {
  39. public:
  40. /// The type of a UDP endpoint.
  41. typedef basic_endpoint<udp> endpoint;
  42. /// Construct to represent the IPv4 UDP protocol.
  43. static udp v4() BOOST_ASIO_NOEXCEPT
  44. {
  45. return udp(BOOST_ASIO_OS_DEF(AF_INET));
  46. }
  47. /// Construct to represent the IPv6 UDP protocol.
  48. static udp v6() BOOST_ASIO_NOEXCEPT
  49. {
  50. return udp(BOOST_ASIO_OS_DEF(AF_INET6));
  51. }
  52. /// Obtain an identifier for the type of the protocol.
  53. int type() const BOOST_ASIO_NOEXCEPT
  54. {
  55. return BOOST_ASIO_OS_DEF(SOCK_DGRAM);
  56. }
  57. /// Obtain an identifier for the protocol.
  58. int protocol() const BOOST_ASIO_NOEXCEPT
  59. {
  60. return BOOST_ASIO_OS_DEF(IPPROTO_UDP);
  61. }
  62. /// Obtain an identifier for the protocol family.
  63. int family() const BOOST_ASIO_NOEXCEPT
  64. {
  65. return family_;
  66. }
  67. /// The UDP socket type.
  68. typedef basic_datagram_socket<udp> socket;
  69. /// The UDP resolver type.
  70. typedef basic_resolver<udp> resolver;
  71. /// Compare two protocols for equality.
  72. friend bool operator==(const udp& p1, const udp& p2)
  73. {
  74. return p1.family_ == p2.family_;
  75. }
  76. /// Compare two protocols for inequality.
  77. friend bool operator!=(const udp& p1, const udp& p2)
  78. {
  79. return p1.family_ != p2.family_;
  80. }
  81. private:
  82. // Construct with a specific family.
  83. explicit udp(int protocol_family) BOOST_ASIO_NOEXCEPT
  84. : family_(protocol_family)
  85. {
  86. }
  87. int family_;
  88. };
  89. } // namespace ip
  90. } // namespace asio
  91. } // namespace boost
  92. #include <boost/asio/detail/pop_options.hpp>
  93. #endif // BOOST_ASIO_IP_UDP_HPP