Chris@16: // Chris@16: // local/detail/endpoint.hpp Chris@16: // ~~~~~~~~~~~~~~~~~~~~~~~~~ Chris@16: // Chris@101: // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) Chris@16: // Derived from a public domain implementation written by Daniel Casimiro. Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: Chris@16: #ifndef BOOST_ASIO_LOCAL_DETAIL_ENDPOINT_HPP Chris@16: #define BOOST_ASIO_LOCAL_DETAIL_ENDPOINT_HPP Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: # pragma once Chris@16: #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: Chris@16: #include Chris@16: Chris@16: #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace asio { Chris@16: namespace local { Chris@16: namespace detail { Chris@16: Chris@16: // Helper class for implementing a UNIX domain endpoint. Chris@16: class endpoint Chris@16: { Chris@16: public: Chris@16: // Default constructor. Chris@16: BOOST_ASIO_DECL endpoint(); Chris@16: Chris@16: // Construct an endpoint using the specified path name. Chris@16: BOOST_ASIO_DECL endpoint(const char* path_name); Chris@16: Chris@16: // Construct an endpoint using the specified path name. Chris@16: BOOST_ASIO_DECL endpoint(const std::string& path_name); Chris@16: Chris@16: // Copy constructor. Chris@16: endpoint(const endpoint& other) Chris@16: : data_(other.data_), Chris@16: path_length_(other.path_length_) Chris@16: { Chris@16: } Chris@16: Chris@16: // Assign from another endpoint. Chris@16: endpoint& operator=(const endpoint& other) Chris@16: { Chris@16: data_ = other.data_; Chris@16: path_length_ = other.path_length_; Chris@16: return *this; Chris@16: } Chris@16: Chris@16: // Get the underlying endpoint in the native type. Chris@16: boost::asio::detail::socket_addr_type* data() Chris@16: { Chris@16: return &data_.base; Chris@16: } Chris@16: Chris@16: // Get the underlying endpoint in the native type. Chris@16: const boost::asio::detail::socket_addr_type* data() const Chris@16: { Chris@16: return &data_.base; Chris@16: } Chris@16: Chris@16: // Get the underlying size of the endpoint in the native type. Chris@16: std::size_t size() const Chris@16: { Chris@16: return path_length_ Chris@16: + offsetof(boost::asio::detail::sockaddr_un_type, sun_path); Chris@16: } Chris@16: Chris@16: // Set the underlying size of the endpoint in the native type. Chris@16: BOOST_ASIO_DECL void resize(std::size_t size); Chris@16: Chris@16: // Get the capacity of the endpoint in the native type. Chris@16: std::size_t capacity() const Chris@16: { Chris@16: return sizeof(boost::asio::detail::sockaddr_un_type); Chris@16: } Chris@16: Chris@16: // Get the path associated with the endpoint. Chris@16: BOOST_ASIO_DECL std::string path() const; Chris@16: Chris@16: // Set the path associated with the endpoint. Chris@16: BOOST_ASIO_DECL void path(const char* p); Chris@16: Chris@16: // Set the path associated with the endpoint. Chris@16: BOOST_ASIO_DECL void path(const std::string& p); Chris@16: Chris@16: // Compare two endpoints for equality. Chris@16: BOOST_ASIO_DECL friend bool operator==( Chris@16: const endpoint& e1, const endpoint& e2); Chris@16: Chris@16: // Compare endpoints for ordering. Chris@16: BOOST_ASIO_DECL friend bool operator<( Chris@16: const endpoint& e1, const endpoint& e2); Chris@16: Chris@16: private: Chris@16: // The underlying UNIX socket address. Chris@16: union data_union Chris@16: { Chris@16: boost::asio::detail::socket_addr_type base; Chris@16: boost::asio::detail::sockaddr_un_type local; Chris@16: } data_; Chris@16: Chris@16: // The length of the path associated with the endpoint. Chris@16: std::size_t path_length_; Chris@16: Chris@16: // Initialise with a specified path. Chris@16: BOOST_ASIO_DECL void init(const char* path, std::size_t path_length); Chris@16: }; Chris@16: Chris@16: } // namespace detail Chris@16: } // namespace local Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #if defined(BOOST_ASIO_HEADER_ONLY) Chris@16: # include Chris@16: #endif // defined(BOOST_ASIO_HEADER_ONLY) Chris@16: Chris@16: #endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) Chris@16: Chris@16: #endif // BOOST_ASIO_LOCAL_DETAIL_ENDPOINT_HPP