2 // generic/basic_endpoint.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef BOOST_ASIO_GENERIC_BASIC_ENDPOINT_HPP
12 #define BOOST_ASIO_GENERIC_BASIC_ENDPOINT_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
19 #include <boost/asio/generic/detail/endpoint.hpp>
21 #include <boost/asio/detail/push_options.hpp>
27 /// Describes an endpoint for any socket type.
29 * The boost::asio::generic::basic_endpoint class template describes an endpoint
30 * that may be associated with any socket type.
32 * @note The socket types sockaddr type must be able to fit into a
33 * @c sockaddr_storage structure.
36 * @e Distinct @e objects: Safe.@n
37 * @e Shared @e objects: Unsafe.
42 template <typename Protocol>
46 /// The protocol type associated with the endpoint.
47 typedef Protocol protocol_type;
49 /// The type of the endpoint structure. This type is dependent on the
50 /// underlying implementation of the socket layer.
51 #if defined(GENERATING_DOCUMENTATION)
52 typedef implementation_defined data_type;
54 typedef boost::asio::detail::socket_addr_type data_type;
57 /// Default constructor.
58 basic_endpoint() BOOST_ASIO_NOEXCEPT
62 /// Construct an endpoint from the specified socket address.
63 basic_endpoint(const void* socket_address,
64 std::size_t socket_address_size, int socket_protocol = 0)
65 : impl_(socket_address, socket_address_size, socket_protocol)
69 /// Construct an endpoint from the specific endpoint type.
70 template <typename Endpoint>
71 basic_endpoint(const Endpoint& endpoint)
72 : impl_(endpoint.data(), endpoint.size(), endpoint.protocol().protocol())
77 basic_endpoint(const basic_endpoint& other)
82 #if defined(BOOST_ASIO_HAS_MOVE)
84 basic_endpoint(basic_endpoint&& other)
88 #endif // defined(BOOST_ASIO_HAS_MOVE)
90 /// Assign from another endpoint.
91 basic_endpoint& operator=(const basic_endpoint& other)
97 #if defined(BOOST_ASIO_HAS_MOVE)
98 /// Move-assign from another endpoint.
99 basic_endpoint& operator=(basic_endpoint&& other)
104 #endif // defined(BOOST_ASIO_HAS_MOVE)
106 /// The protocol associated with the endpoint.
107 protocol_type protocol() const
109 return protocol_type(impl_.family(), impl_.protocol());
112 /// Get the underlying endpoint in the native type.
118 /// Get the underlying endpoint in the native type.
119 const data_type* data() const
124 /// Get the underlying size of the endpoint in the native type.
125 std::size_t size() const
130 /// Set the underlying size of the endpoint in the native type.
131 void resize(std::size_t new_size)
133 impl_.resize(new_size);
136 /// Get the capacity of the endpoint in the native type.
137 std::size_t capacity() const
139 return impl_.capacity();
142 /// Compare two endpoints for equality.
143 friend bool operator==(const basic_endpoint<Protocol>& e1,
144 const basic_endpoint<Protocol>& e2)
146 return e1.impl_ == e2.impl_;
149 /// Compare two endpoints for inequality.
150 friend bool operator!=(const basic_endpoint<Protocol>& e1,
151 const basic_endpoint<Protocol>& e2)
153 return !(e1.impl_ == e2.impl_);
156 /// Compare endpoints for ordering.
157 friend bool operator<(const basic_endpoint<Protocol>& e1,
158 const basic_endpoint<Protocol>& e2)
160 return e1.impl_ < e2.impl_;
163 /// Compare endpoints for ordering.
164 friend bool operator>(const basic_endpoint<Protocol>& e1,
165 const basic_endpoint<Protocol>& e2)
167 return e2.impl_ < e1.impl_;
170 /// Compare endpoints for ordering.
171 friend bool operator<=(const basic_endpoint<Protocol>& e1,
172 const basic_endpoint<Protocol>& e2)
177 /// Compare endpoints for ordering.
178 friend bool operator>=(const basic_endpoint<Protocol>& e1,
179 const basic_endpoint<Protocol>& e2)
185 // The underlying generic endpoint.
186 boost::asio::generic::detail::endpoint impl_;
189 } // namespace generic
193 #include <boost/asio/detail/pop_options.hpp>
195 #endif // BOOST_ASIO_GENERIC_BASIC_ENDPOINT_HPP