Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:00

0001 //
0002 // local/detail/endpoint.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 // Derived from a public domain implementation written by Daniel Casimiro.
0007 //
0008 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0009 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0010 //
0011 
0012 #ifndef BOOST_ASIO_LOCAL_DETAIL_ENDPOINT_HPP
0013 #define BOOST_ASIO_LOCAL_DETAIL_ENDPOINT_HPP
0014 
0015 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0016 # pragma once
0017 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0018 
0019 #include <boost/asio/detail/config.hpp>
0020 
0021 #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
0022 
0023 #include <cstddef>
0024 #include <string>
0025 #include <boost/asio/detail/socket_types.hpp>
0026 #include <boost/asio/detail/string_view.hpp>
0027 
0028 #include <boost/asio/detail/push_options.hpp>
0029 
0030 namespace boost {
0031 namespace asio {
0032 namespace local {
0033 namespace detail {
0034 
0035 // Helper class for implementing a UNIX domain endpoint.
0036 class endpoint
0037 {
0038 public:
0039   // Default constructor.
0040   BOOST_ASIO_DECL endpoint();
0041 
0042   // Construct an endpoint using the specified path name.
0043   BOOST_ASIO_DECL endpoint(const char* path_name);
0044 
0045   // Construct an endpoint using the specified path name.
0046   BOOST_ASIO_DECL endpoint(const std::string& path_name);
0047 
0048   #if defined(BOOST_ASIO_HAS_STRING_VIEW)
0049   // Construct an endpoint using the specified path name.
0050   BOOST_ASIO_DECL endpoint(string_view path_name);
0051   #endif // defined(BOOST_ASIO_HAS_STRING_VIEW)
0052 
0053   // Copy constructor.
0054   endpoint(const endpoint& other)
0055     : data_(other.data_),
0056       path_length_(other.path_length_)
0057   {
0058   }
0059 
0060   // Assign from another endpoint.
0061   endpoint& operator=(const endpoint& other)
0062   {
0063     data_ = other.data_;
0064     path_length_ = other.path_length_;
0065     return *this;
0066   }
0067 
0068   // Get the underlying endpoint in the native type.
0069   boost::asio::detail::socket_addr_type* data()
0070   {
0071     return &data_.base;
0072   }
0073 
0074   // Get the underlying endpoint in the native type.
0075   const boost::asio::detail::socket_addr_type* data() const
0076   {
0077     return &data_.base;
0078   }
0079 
0080   // Get the underlying size of the endpoint in the native type.
0081   std::size_t size() const
0082   {
0083     return path_length_
0084       + offsetof(boost::asio::detail::sockaddr_un_type, sun_path);
0085   }
0086 
0087   // Set the underlying size of the endpoint in the native type.
0088   BOOST_ASIO_DECL void resize(std::size_t size);
0089 
0090   // Get the capacity of the endpoint in the native type.
0091   std::size_t capacity() const
0092   {
0093     return sizeof(boost::asio::detail::sockaddr_un_type);
0094   }
0095 
0096   // Get the path associated with the endpoint.
0097   BOOST_ASIO_DECL std::string path() const;
0098 
0099   // Set the path associated with the endpoint.
0100   BOOST_ASIO_DECL void path(const char* p);
0101 
0102   // Set the path associated with the endpoint.
0103   BOOST_ASIO_DECL void path(const std::string& p);
0104 
0105   // Compare two endpoints for equality.
0106   BOOST_ASIO_DECL friend bool operator==(
0107       const endpoint& e1, const endpoint& e2);
0108 
0109   // Compare endpoints for ordering.
0110   BOOST_ASIO_DECL friend bool operator<(
0111       const endpoint& e1, const endpoint& e2);
0112 
0113 private:
0114   // The underlying UNIX socket address.
0115   union data_union
0116   {
0117     boost::asio::detail::socket_addr_type base;
0118     boost::asio::detail::sockaddr_un_type local;
0119   } data_;
0120 
0121   // The length of the path associated with the endpoint.
0122   std::size_t path_length_;
0123 
0124   // Initialise with a specified path.
0125   BOOST_ASIO_DECL void init(const char* path, std::size_t path_length);
0126 };
0127 
0128 } // namespace detail
0129 } // namespace local
0130 } // namespace asio
0131 } // namespace boost
0132 
0133 #include <boost/asio/detail/pop_options.hpp>
0134 
0135 #if defined(BOOST_ASIO_HEADER_ONLY)
0136 # include <boost/asio/local/detail/impl/endpoint.ipp>
0137 #endif // defined(BOOST_ASIO_HEADER_ONLY)
0138 
0139 #endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
0140 
0141 #endif // BOOST_ASIO_LOCAL_DETAIL_ENDPOINT_HPP