Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:53

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