2 // local/detail/endpoint.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2022 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_DETAIL_ENDPOINT_HPP
13 #define BOOST_ASIO_LOCAL_DETAIL_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)
25 #include <boost/asio/detail/socket_types.hpp>
26 #include <boost/asio/detail/string_view.hpp>
28 #include <boost/asio/detail/push_options.hpp>
35 // Helper class for implementing a UNIX domain endpoint.
39 // Default constructor.
40 BOOST_ASIO_DECL endpoint();
42 // Construct an endpoint using the specified path name.
43 BOOST_ASIO_DECL endpoint(const char* path_name);
45 // Construct an endpoint using the specified path name.
46 BOOST_ASIO_DECL endpoint(const std::string& path_name);
48 #if defined(BOOST_ASIO_HAS_STRING_VIEW)
49 // Construct an endpoint using the specified path name.
50 BOOST_ASIO_DECL endpoint(string_view path_name);
51 #endif // defined(BOOST_ASIO_HAS_STRING_VIEW)
54 endpoint(const endpoint& other)
56 path_length_(other.path_length_)
60 // Assign from another endpoint.
61 endpoint& operator=(const endpoint& other)
64 path_length_ = other.path_length_;
68 // Get the underlying endpoint in the native type.
69 boost::asio::detail::socket_addr_type* data()
74 // Get the underlying endpoint in the native type.
75 const boost::asio::detail::socket_addr_type* data() const
80 // Get the underlying size of the endpoint in the native type.
81 std::size_t size() const
84 + offsetof(boost::asio::detail::sockaddr_un_type, sun_path);
87 // Set the underlying size of the endpoint in the native type.
88 BOOST_ASIO_DECL void resize(std::size_t size);
90 // Get the capacity of the endpoint in the native type.
91 std::size_t capacity() const
93 return sizeof(boost::asio::detail::sockaddr_un_type);
96 // Get the path associated with the endpoint.
97 BOOST_ASIO_DECL std::string path() const;
99 // Set the path associated with the endpoint.
100 BOOST_ASIO_DECL void path(const char* p);
102 // Set the path associated with the endpoint.
103 BOOST_ASIO_DECL void path(const std::string& p);
105 // Compare two endpoints for equality.
106 BOOST_ASIO_DECL friend bool operator==(
107 const endpoint& e1, const endpoint& e2);
109 // Compare endpoints for ordering.
110 BOOST_ASIO_DECL friend bool operator<(
111 const endpoint& e1, const endpoint& e2);
114 // The underlying UNIX socket address.
117 boost::asio::detail::socket_addr_type base;
118 boost::asio::detail::sockaddr_un_type local;
121 // The length of the path associated with the endpoint.
122 std::size_t path_length_;
124 // Initialise with a specified path.
125 BOOST_ASIO_DECL void init(const char* path, std::size_t path_length);
128 } // namespace detail
133 #include <boost/asio/detail/pop_options.hpp>
135 #if defined(BOOST_ASIO_HEADER_ONLY)
136 # include <boost/asio/local/detail/impl/endpoint.ipp>
137 #endif // defined(BOOST_ASIO_HEADER_ONLY)
139 #endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
141 #endif // BOOST_ASIO_LOCAL_DETAIL_ENDPOINT_HPP