2 // local/basic_endpoint.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 // Derived from a public domain implementation written by Daniel Casimiro.
8 // Distributed under the Boost Software License, Version 1.0. (See accompanying
9 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
12 #ifndef BOOST_ASIO_LOCAL_BASIC_ENDPOINT_HPP
13 #define BOOST_ASIO_LOCAL_BASIC_ENDPOINT_HPP
15 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
17 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
19 #include <boost/asio/detail/config.hpp>
21 #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) \
22 || defined(GENERATING_DOCUMENTATION)
24 #include <boost/asio/local/detail/endpoint.hpp>
26 #if !defined(BOOST_ASIO_NO_IOSTREAM)
28 #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
30 #include <boost/asio/detail/push_options.hpp>
36 /// Describes an endpoint for a UNIX socket.
38 * The boost::asio::local::basic_endpoint class template describes an endpoint
39 * that may be associated with a particular UNIX socket.
42 * @e Distinct @e objects: Safe.@n
43 * @e Shared @e objects: Unsafe.
48 template <typename Protocol>
52 /// The protocol type associated with the endpoint.
53 typedef Protocol protocol_type;
55 /// The type of the endpoint structure. This type is dependent on the
56 /// underlying implementation of the socket layer.
57 #if defined(GENERATING_DOCUMENTATION)
58 typedef implementation_defined data_type;
60 typedef boost::asio::detail::socket_addr_type data_type;
63 /// Default constructor.
64 basic_endpoint() BOOST_ASIO_NOEXCEPT
68 /// Construct an endpoint using the specified path name.
69 basic_endpoint(const char* path_name)
74 /// Construct an endpoint using the specified path name.
75 basic_endpoint(const std::string& path_name)
80 #if defined(BOOST_ASIO_HAS_STRING_VIEW)
81 /// Construct an endpoint using the specified path name.
82 basic_endpoint(string_view path_name)
86 #endif // defined(BOOST_ASIO_HAS_STRING_VIEW)
89 basic_endpoint(const basic_endpoint& other)
94 #if defined(BOOST_ASIO_HAS_MOVE)
96 basic_endpoint(basic_endpoint&& other)
100 #endif // defined(BOOST_ASIO_HAS_MOVE)
102 /// Assign from another endpoint.
103 basic_endpoint& operator=(const basic_endpoint& other)
109 #if defined(BOOST_ASIO_HAS_MOVE)
110 /// Move-assign from another endpoint.
111 basic_endpoint& operator=(basic_endpoint&& other)
116 #endif // defined(BOOST_ASIO_HAS_MOVE)
118 /// The protocol associated with the endpoint.
119 protocol_type protocol() const
121 return protocol_type();
124 /// Get the underlying endpoint in the native type.
130 /// Get the underlying endpoint in the native type.
131 const data_type* data() const
136 /// Get the underlying size of the endpoint in the native type.
137 std::size_t size() const
142 /// Set the underlying size of the endpoint in the native type.
143 void resize(std::size_t new_size)
145 impl_.resize(new_size);
148 /// Get the capacity of the endpoint in the native type.
149 std::size_t capacity() const
151 return impl_.capacity();
154 /// Get the path associated with the endpoint.
155 std::string path() const
160 /// Set the path associated with the endpoint.
161 void path(const char* p)
166 /// Set the path associated with the endpoint.
167 void path(const std::string& p)
172 /// Compare two endpoints for equality.
173 friend bool operator==(const basic_endpoint<Protocol>& e1,
174 const basic_endpoint<Protocol>& e2)
176 return e1.impl_ == e2.impl_;
179 /// Compare two endpoints for inequality.
180 friend bool operator!=(const basic_endpoint<Protocol>& e1,
181 const basic_endpoint<Protocol>& e2)
183 return !(e1.impl_ == e2.impl_);
186 /// Compare endpoints for ordering.
187 friend bool operator<(const basic_endpoint<Protocol>& e1,
188 const basic_endpoint<Protocol>& e2)
190 return e1.impl_ < e2.impl_;
193 /// Compare endpoints for ordering.
194 friend bool operator>(const basic_endpoint<Protocol>& e1,
195 const basic_endpoint<Protocol>& e2)
197 return e2.impl_ < e1.impl_;
200 /// Compare endpoints for ordering.
201 friend bool operator<=(const basic_endpoint<Protocol>& e1,
202 const basic_endpoint<Protocol>& e2)
207 /// Compare endpoints for ordering.
208 friend bool operator>=(const basic_endpoint<Protocol>& e1,
209 const basic_endpoint<Protocol>& e2)
215 // The underlying UNIX domain endpoint.
216 boost::asio::local::detail::endpoint impl_;
219 /// Output an endpoint as a string.
221 * Used to output a human-readable string for a specified endpoint.
223 * @param os The output stream to which the string will be written.
225 * @param endpoint The endpoint to be written.
227 * @return The output stream.
229 * @relates boost::asio::local::basic_endpoint
231 template <typename Elem, typename Traits, typename Protocol>
232 std::basic_ostream<Elem, Traits>& operator<<(
233 std::basic_ostream<Elem, Traits>& os,
234 const basic_endpoint<Protocol>& endpoint)
236 os << endpoint.path();
244 #include <boost/asio/detail/pop_options.hpp>
246 #endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
247 // || defined(GENERATING_DOCUMENTATION)
249 #endif // BOOST_ASIO_LOCAL_BASIC_ENDPOINT_HPP