File indexing completed on 2025-01-18 09:28:59
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_IP_DETAIL_ENDPOINT_HPP
0012 #define BOOST_ASIO_IP_DETAIL_ENDPOINT_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019 #include <string>
0020 #include <boost/asio/detail/socket_types.hpp>
0021 #include <boost/asio/detail/winsock_init.hpp>
0022 #include <boost/system/error_code.hpp>
0023 #include <boost/asio/ip/address.hpp>
0024
0025 #include <boost/asio/detail/push_options.hpp>
0026
0027 namespace boost {
0028 namespace asio {
0029 namespace ip {
0030 namespace detail {
0031
0032
0033 class endpoint
0034 {
0035 public:
0036
0037 BOOST_ASIO_DECL endpoint() noexcept;
0038
0039
0040 BOOST_ASIO_DECL endpoint(int family,
0041 unsigned short port_num) noexcept;
0042
0043
0044 BOOST_ASIO_DECL endpoint(const boost::asio::ip::address& addr,
0045 unsigned short port_num) noexcept;
0046
0047
0048 endpoint(const endpoint& other) noexcept
0049 : data_(other.data_)
0050 {
0051 }
0052
0053
0054 endpoint& operator=(const endpoint& other) noexcept
0055 {
0056 data_ = other.data_;
0057 return *this;
0058 }
0059
0060
0061 boost::asio::detail::socket_addr_type* data() noexcept
0062 {
0063 return &data_.base;
0064 }
0065
0066
0067 const boost::asio::detail::socket_addr_type* data() const noexcept
0068 {
0069 return &data_.base;
0070 }
0071
0072
0073 std::size_t size() const noexcept
0074 {
0075 if (is_v4())
0076 return sizeof(boost::asio::detail::sockaddr_in4_type);
0077 else
0078 return sizeof(boost::asio::detail::sockaddr_in6_type);
0079 }
0080
0081
0082 BOOST_ASIO_DECL void resize(std::size_t new_size);
0083
0084
0085 std::size_t capacity() const noexcept
0086 {
0087 return sizeof(data_);
0088 }
0089
0090
0091 BOOST_ASIO_DECL unsigned short port() const noexcept;
0092
0093
0094 BOOST_ASIO_DECL void port(unsigned short port_num) noexcept;
0095
0096
0097 BOOST_ASIO_DECL boost::asio::ip::address address() const noexcept;
0098
0099
0100 BOOST_ASIO_DECL void address(
0101 const boost::asio::ip::address& addr) noexcept;
0102
0103
0104 BOOST_ASIO_DECL friend bool operator==(const endpoint& e1,
0105 const endpoint& e2) noexcept;
0106
0107
0108 BOOST_ASIO_DECL friend bool operator<(const endpoint& e1,
0109 const endpoint& e2) noexcept;
0110
0111
0112 bool is_v4() const noexcept
0113 {
0114 return data_.base.sa_family == BOOST_ASIO_OS_DEF(AF_INET);
0115 }
0116
0117 #if !defined(BOOST_ASIO_NO_IOSTREAM)
0118
0119 BOOST_ASIO_DECL std::string to_string() const;
0120 #endif
0121
0122 private:
0123
0124 union data_union
0125 {
0126 boost::asio::detail::socket_addr_type base;
0127 boost::asio::detail::sockaddr_in4_type v4;
0128 boost::asio::detail::sockaddr_in6_type v6;
0129 } data_;
0130 };
0131
0132 }
0133 }
0134 }
0135 }
0136
0137 #include <boost/asio/detail/pop_options.hpp>
0138
0139 #if defined(BOOST_ASIO_HEADER_ONLY)
0140 # include <boost/asio/ip/detail/impl/endpoint.ipp>
0141 #endif
0142
0143 #endif