udp.hpp 2.5 KB

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