annotate DEPENDENCIES/generic/include/boost/asio/ip/detail/endpoint.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 //
Chris@16 2 // ip/detail/endpoint.hpp
Chris@16 3 // ~~~~~~~~~~~~~~~~~~~~~~
Chris@16 4 //
Chris@101 5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
Chris@16 6 //
Chris@16 7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
Chris@16 8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 9 //
Chris@16 10
Chris@16 11 #ifndef BOOST_ASIO_IP_DETAIL_ENDPOINT_HPP
Chris@16 12 #define BOOST_ASIO_IP_DETAIL_ENDPOINT_HPP
Chris@16 13
Chris@16 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
Chris@16 15 # pragma once
Chris@16 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
Chris@16 17
Chris@16 18 #include <boost/asio/detail/config.hpp>
Chris@16 19 #include <string>
Chris@16 20 #include <boost/asio/detail/socket_types.hpp>
Chris@16 21 #include <boost/asio/detail/winsock_init.hpp>
Chris@16 22 #include <boost/system/error_code.hpp>
Chris@16 23 #include <boost/asio/ip/address.hpp>
Chris@16 24
Chris@16 25 #include <boost/asio/detail/push_options.hpp>
Chris@16 26
Chris@16 27 namespace boost {
Chris@16 28 namespace asio {
Chris@16 29 namespace ip {
Chris@16 30 namespace detail {
Chris@16 31
Chris@16 32 // Helper class for implementating an IP endpoint.
Chris@16 33 class endpoint
Chris@16 34 {
Chris@16 35 public:
Chris@16 36 // Default constructor.
Chris@16 37 BOOST_ASIO_DECL endpoint();
Chris@16 38
Chris@16 39 // Construct an endpoint using a family and port number.
Chris@16 40 BOOST_ASIO_DECL endpoint(int family, unsigned short port_num);
Chris@16 41
Chris@16 42 // Construct an endpoint using an address and port number.
Chris@16 43 BOOST_ASIO_DECL endpoint(const boost::asio::ip::address& addr,
Chris@16 44 unsigned short port_num);
Chris@16 45
Chris@16 46 // Copy constructor.
Chris@16 47 endpoint(const endpoint& other)
Chris@16 48 : data_(other.data_)
Chris@16 49 {
Chris@16 50 }
Chris@16 51
Chris@16 52 // Assign from another endpoint.
Chris@16 53 endpoint& operator=(const endpoint& other)
Chris@16 54 {
Chris@16 55 data_ = other.data_;
Chris@16 56 return *this;
Chris@16 57 }
Chris@16 58
Chris@16 59 // Get the underlying endpoint in the native type.
Chris@16 60 boost::asio::detail::socket_addr_type* data()
Chris@16 61 {
Chris@16 62 return &data_.base;
Chris@16 63 }
Chris@16 64
Chris@16 65 // Get the underlying endpoint in the native type.
Chris@16 66 const boost::asio::detail::socket_addr_type* data() const
Chris@16 67 {
Chris@16 68 return &data_.base;
Chris@16 69 }
Chris@16 70
Chris@16 71 // Get the underlying size of the endpoint in the native type.
Chris@16 72 std::size_t size() const
Chris@16 73 {
Chris@16 74 if (is_v4())
Chris@16 75 return sizeof(boost::asio::detail::sockaddr_in4_type);
Chris@16 76 else
Chris@16 77 return sizeof(boost::asio::detail::sockaddr_in6_type);
Chris@16 78 }
Chris@16 79
Chris@16 80 // Set the underlying size of the endpoint in the native type.
Chris@16 81 BOOST_ASIO_DECL void resize(std::size_t new_size);
Chris@16 82
Chris@16 83 // Get the capacity of the endpoint in the native type.
Chris@16 84 std::size_t capacity() const
Chris@16 85 {
Chris@16 86 return sizeof(data_);
Chris@16 87 }
Chris@16 88
Chris@16 89 // Get the port associated with the endpoint.
Chris@16 90 BOOST_ASIO_DECL unsigned short port() const;
Chris@16 91
Chris@16 92 // Set the port associated with the endpoint.
Chris@16 93 BOOST_ASIO_DECL void port(unsigned short port_num);
Chris@16 94
Chris@16 95 // Get the IP address associated with the endpoint.
Chris@16 96 BOOST_ASIO_DECL boost::asio::ip::address address() const;
Chris@16 97
Chris@16 98 // Set the IP address associated with the endpoint.
Chris@16 99 BOOST_ASIO_DECL void address(const boost::asio::ip::address& addr);
Chris@16 100
Chris@16 101 // Compare two endpoints for equality.
Chris@16 102 BOOST_ASIO_DECL friend bool operator==(
Chris@16 103 const endpoint& e1, const endpoint& e2);
Chris@16 104
Chris@16 105 // Compare endpoints for ordering.
Chris@16 106 BOOST_ASIO_DECL friend bool operator<(
Chris@16 107 const endpoint& e1, const endpoint& e2);
Chris@16 108
Chris@16 109 // Determine whether the endpoint is IPv4.
Chris@16 110 bool is_v4() const
Chris@16 111 {
Chris@16 112 return data_.base.sa_family == BOOST_ASIO_OS_DEF(AF_INET);
Chris@16 113 }
Chris@16 114
Chris@16 115 #if !defined(BOOST_ASIO_NO_IOSTREAM)
Chris@16 116 // Convert to a string.
Chris@16 117 BOOST_ASIO_DECL std::string to_string(boost::system::error_code& ec) const;
Chris@16 118 #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
Chris@16 119
Chris@16 120 private:
Chris@16 121 // The underlying IP socket address.
Chris@16 122 union data_union
Chris@16 123 {
Chris@16 124 boost::asio::detail::socket_addr_type base;
Chris@16 125 boost::asio::detail::sockaddr_in4_type v4;
Chris@16 126 boost::asio::detail::sockaddr_in6_type v6;
Chris@16 127 } data_;
Chris@16 128 };
Chris@16 129
Chris@16 130 } // namespace detail
Chris@16 131 } // namespace ip
Chris@16 132 } // namespace asio
Chris@16 133 } // namespace boost
Chris@16 134
Chris@16 135 #include <boost/asio/detail/pop_options.hpp>
Chris@16 136
Chris@16 137 #if defined(BOOST_ASIO_HEADER_ONLY)
Chris@16 138 # include <boost/asio/ip/detail/impl/endpoint.ipp>
Chris@16 139 #endif // defined(BOOST_ASIO_HEADER_ONLY)
Chris@16 140
Chris@16 141 #endif // BOOST_ASIO_IP_DETAIL_ENDPOINT_HPP