Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //
0002 // generic/basic_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_BASIC_ENDPOINT_HPP
0012 #define BOOST_ASIO_GENERIC_BASIC_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 #include <boost/asio/generic/detail/endpoint.hpp>
0020 
0021 #include <boost/asio/detail/push_options.hpp>
0022 
0023 namespace boost {
0024 namespace asio {
0025 namespace generic {
0026 
0027 /// Describes an endpoint for any socket type.
0028 /**
0029  * The boost::asio::generic::basic_endpoint class template describes an endpoint
0030  * that may be associated with any socket type.
0031  *
0032  * @note The socket types sockaddr type must be able to fit into a
0033  * @c sockaddr_storage structure.
0034  *
0035  * @par Thread Safety
0036  * @e Distinct @e objects: Safe.@n
0037  * @e Shared @e objects: Unsafe.
0038  *
0039  * @par Concepts:
0040  * Endpoint.
0041  */
0042 template <typename Protocol>
0043 class basic_endpoint
0044 {
0045 public:
0046   /// The protocol type associated with the endpoint.
0047   typedef Protocol protocol_type;
0048 
0049   /// The type of the endpoint structure. This type is dependent on the
0050   /// underlying implementation of the socket layer.
0051 #if defined(GENERATING_DOCUMENTATION)
0052   typedef implementation_defined data_type;
0053 #else
0054   typedef boost::asio::detail::socket_addr_type data_type;
0055 #endif
0056 
0057   /// Default constructor.
0058   basic_endpoint() noexcept
0059   {
0060   }
0061 
0062   /// Construct an endpoint from the specified socket address.
0063   basic_endpoint(const void* socket_address,
0064       std::size_t socket_address_size, int socket_protocol = 0)
0065     : impl_(socket_address, socket_address_size, socket_protocol)
0066   {
0067   }
0068 
0069   /// Construct an endpoint from the specific endpoint type.
0070   template <typename Endpoint>
0071   basic_endpoint(const Endpoint& endpoint)
0072     : impl_(endpoint.data(), endpoint.size(), endpoint.protocol().protocol())
0073   {
0074   }
0075 
0076   /// Copy constructor.
0077   basic_endpoint(const basic_endpoint& other)
0078     : impl_(other.impl_)
0079   {
0080   }
0081 
0082   /// Move constructor.
0083   basic_endpoint(basic_endpoint&& other)
0084     : impl_(other.impl_)
0085   {
0086   }
0087 
0088   /// Assign from another endpoint.
0089   basic_endpoint& operator=(const basic_endpoint& other)
0090   {
0091     impl_ = other.impl_;
0092     return *this;
0093   }
0094 
0095   /// Move-assign from another endpoint.
0096   basic_endpoint& operator=(basic_endpoint&& other)
0097   {
0098     impl_ = other.impl_;
0099     return *this;
0100   }
0101 
0102   /// The protocol associated with the endpoint.
0103   protocol_type protocol() const
0104   {
0105     return protocol_type(impl_.family(), impl_.protocol());
0106   }
0107 
0108   /// Get the underlying endpoint in the native type.
0109   data_type* data()
0110   {
0111     return impl_.data();
0112   }
0113 
0114   /// Get the underlying endpoint in the native type.
0115   const data_type* data() const
0116   {
0117     return impl_.data();
0118   }
0119 
0120   /// Get the underlying size of the endpoint in the native type.
0121   std::size_t size() const
0122   {
0123     return impl_.size();
0124   }
0125 
0126   /// Set the underlying size of the endpoint in the native type.
0127   void resize(std::size_t new_size)
0128   {
0129     impl_.resize(new_size);
0130   }
0131 
0132   /// Get the capacity of the endpoint in the native type.
0133   std::size_t capacity() const
0134   {
0135     return impl_.capacity();
0136   }
0137 
0138   /// Compare two endpoints for equality.
0139   friend bool operator==(const basic_endpoint<Protocol>& e1,
0140       const basic_endpoint<Protocol>& e2)
0141   {
0142     return e1.impl_ == e2.impl_;
0143   }
0144 
0145   /// Compare two endpoints for inequality.
0146   friend bool operator!=(const basic_endpoint<Protocol>& e1,
0147       const basic_endpoint<Protocol>& e2)
0148   {
0149     return !(e1.impl_ == e2.impl_);
0150   }
0151 
0152   /// Compare endpoints for ordering.
0153   friend bool operator<(const basic_endpoint<Protocol>& e1,
0154       const basic_endpoint<Protocol>& e2)
0155   {
0156     return e1.impl_ < e2.impl_;
0157   }
0158 
0159   /// Compare endpoints for ordering.
0160   friend bool operator>(const basic_endpoint<Protocol>& e1,
0161       const basic_endpoint<Protocol>& e2)
0162   {
0163     return e2.impl_ < e1.impl_;
0164   }
0165 
0166   /// Compare endpoints for ordering.
0167   friend bool operator<=(const basic_endpoint<Protocol>& e1,
0168       const basic_endpoint<Protocol>& e2)
0169   {
0170     return !(e2 < e1);
0171   }
0172 
0173   /// Compare endpoints for ordering.
0174   friend bool operator>=(const basic_endpoint<Protocol>& e1,
0175       const basic_endpoint<Protocol>& e2)
0176   {
0177     return !(e1 < e2);
0178   }
0179 
0180 private:
0181   // The underlying generic endpoint.
0182   boost::asio::generic::detail::endpoint impl_;
0183 };
0184 
0185 } // namespace generic
0186 } // namespace asio
0187 } // namespace boost
0188 
0189 #include <boost/asio/detail/pop_options.hpp>
0190 
0191 #endif // BOOST_ASIO_GENERIC_BASIC_ENDPOINT_HPP