File indexing completed on 2025-09-17 08:23:37
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_IP_BASIC_RESOLVER_RESULTS_HPP
0012 #define BOOST_ASIO_IP_BASIC_RESOLVER_RESULTS_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019 #include <cstddef>
0020 #include <cstring>
0021 #include <boost/asio/detail/socket_ops.hpp>
0022 #include <boost/asio/detail/socket_types.hpp>
0023 #include <boost/asio/ip/basic_resolver_iterator.hpp>
0024
0025 #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
0026 # include <boost/asio/detail/winrt_utils.hpp>
0027 #endif
0028
0029 #include <boost/asio/detail/push_options.hpp>
0030
0031 namespace boost {
0032 namespace asio {
0033 namespace ip {
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050 template <typename InternetProtocol>
0051 class basic_resolver_results
0052 : private basic_resolver_iterator<InternetProtocol>
0053 {
0054 public:
0055
0056 typedef InternetProtocol protocol_type;
0057
0058
0059 typedef typename protocol_type::endpoint endpoint_type;
0060
0061
0062 typedef basic_resolver_entry<protocol_type> value_type;
0063
0064
0065 typedef const value_type& const_reference;
0066
0067
0068 typedef value_type& reference;
0069
0070
0071 typedef basic_resolver_iterator<protocol_type> const_iterator;
0072
0073
0074 typedef const_iterator iterator;
0075
0076
0077 typedef std::ptrdiff_t difference_type;
0078
0079
0080 typedef std::size_t size_type;
0081
0082
0083 basic_resolver_results()
0084 {
0085 }
0086
0087
0088 basic_resolver_results(const basic_resolver_results& other)
0089 : basic_resolver_iterator<InternetProtocol>(other)
0090 {
0091 }
0092
0093
0094 basic_resolver_results(basic_resolver_results&& other)
0095 : basic_resolver_iterator<InternetProtocol>(
0096 static_cast<basic_resolver_results&&>(other))
0097 {
0098 }
0099
0100
0101 basic_resolver_results& operator=(const basic_resolver_results& other)
0102 {
0103 basic_resolver_iterator<InternetProtocol>::operator=(other);
0104 return *this;
0105 }
0106
0107
0108 basic_resolver_results& operator=(basic_resolver_results&& other)
0109 {
0110 basic_resolver_iterator<InternetProtocol>::operator=(
0111 static_cast<basic_resolver_results&&>(other));
0112 return *this;
0113 }
0114
0115 #if !defined(GENERATING_DOCUMENTATION)
0116
0117 static basic_resolver_results create(
0118 boost::asio::detail::addrinfo_type* address_info,
0119 const std::string& host_name, const std::string& service_name)
0120 {
0121 basic_resolver_results results;
0122 if (!address_info)
0123 return results;
0124
0125 std::string actual_host_name = host_name;
0126 if (address_info->ai_canonname)
0127 actual_host_name = address_info->ai_canonname;
0128
0129 results.values_.reset(new values_type);
0130
0131 while (address_info)
0132 {
0133 if (address_info->ai_family == BOOST_ASIO_OS_DEF(AF_INET)
0134 || address_info->ai_family == BOOST_ASIO_OS_DEF(AF_INET6))
0135 {
0136 using namespace std;
0137 typename InternetProtocol::endpoint endpoint;
0138 endpoint.resize(static_cast<std::size_t>(address_info->ai_addrlen));
0139 memcpy(endpoint.data(), address_info->ai_addr,
0140 address_info->ai_addrlen);
0141 results.values_->push_back(
0142 basic_resolver_entry<InternetProtocol>(endpoint,
0143 actual_host_name, service_name));
0144 }
0145 address_info = address_info->ai_next;
0146 }
0147
0148 return results;
0149 }
0150
0151
0152 static basic_resolver_results create(const endpoint_type& endpoint,
0153 const std::string& host_name, const std::string& service_name)
0154 {
0155 basic_resolver_results results;
0156 results.values_.reset(new values_type);
0157 results.values_->push_back(
0158 basic_resolver_entry<InternetProtocol>(
0159 endpoint, host_name, service_name));
0160 return results;
0161 }
0162
0163
0164 template <typename EndpointIterator>
0165 static basic_resolver_results create(
0166 EndpointIterator begin, EndpointIterator end,
0167 const std::string& host_name, const std::string& service_name)
0168 {
0169 basic_resolver_results results;
0170 if (begin != end)
0171 {
0172 results.values_.reset(new values_type);
0173 for (EndpointIterator ep_iter = begin; ep_iter != end; ++ep_iter)
0174 {
0175 results.values_->push_back(
0176 basic_resolver_entry<InternetProtocol>(
0177 *ep_iter, host_name, service_name));
0178 }
0179 }
0180 return results;
0181 }
0182
0183 # if defined(BOOST_ASIO_WINDOWS_RUNTIME)
0184
0185 static basic_resolver_results create(
0186 Windows::Foundation::Collections::IVectorView<
0187 Windows::Networking::EndpointPair^>^ endpoints,
0188 const boost::asio::detail::addrinfo_type& hints,
0189 const std::string& host_name, const std::string& service_name)
0190 {
0191 basic_resolver_results results;
0192 if (endpoints->Size)
0193 {
0194 results.values_.reset(new values_type);
0195 for (unsigned int i = 0; i < endpoints->Size; ++i)
0196 {
0197 auto pair = endpoints->GetAt(i);
0198
0199 if (hints.ai_family == BOOST_ASIO_OS_DEF(AF_INET)
0200 && pair->RemoteHostName->Type
0201 != Windows::Networking::HostNameType::Ipv4)
0202 continue;
0203
0204 if (hints.ai_family == BOOST_ASIO_OS_DEF(AF_INET6)
0205 && pair->RemoteHostName->Type
0206 != Windows::Networking::HostNameType::Ipv6)
0207 continue;
0208
0209 results.values_->push_back(
0210 basic_resolver_entry<InternetProtocol>(
0211 typename InternetProtocol::endpoint(
0212 ip::make_address(
0213 boost::asio::detail::winrt_utils::string(
0214 pair->RemoteHostName->CanonicalName)),
0215 boost::asio::detail::winrt_utils::integer(
0216 pair->RemoteServiceName)),
0217 host_name, service_name));
0218 }
0219 }
0220 return results;
0221 }
0222 # endif
0223 #endif
0224
0225
0226 size_type size() const noexcept
0227 {
0228 return this->values_ ? this->values_->size() : 0;
0229 }
0230
0231
0232 size_type max_size() const noexcept
0233 {
0234 return this->values_ ? this->values_->max_size() : values_type().max_size();
0235 }
0236
0237
0238 bool empty() const noexcept
0239 {
0240 return this->values_ ? this->values_->empty() : true;
0241 }
0242
0243
0244 const_iterator begin() const
0245 {
0246 basic_resolver_results tmp(*this);
0247 tmp.index_ = 0;
0248 return static_cast<basic_resolver_results&&>(tmp);
0249 }
0250
0251
0252 const_iterator end() const
0253 {
0254 return const_iterator();
0255 }
0256
0257
0258 const_iterator cbegin() const
0259 {
0260 return begin();
0261 }
0262
0263
0264 const_iterator cend() const
0265 {
0266 return end();
0267 }
0268
0269
0270 void swap(basic_resolver_results& that) noexcept
0271 {
0272 if (this != &that)
0273 {
0274 this->values_.swap(that.values_);
0275 std::size_t index = this->index_;
0276 this->index_ = that.index_;
0277 that.index_ = index;
0278 }
0279 }
0280
0281
0282 friend bool operator==(const basic_resolver_results& a,
0283 const basic_resolver_results& b)
0284 {
0285 return a.equal(b);
0286 }
0287
0288
0289 friend bool operator!=(const basic_resolver_results& a,
0290 const basic_resolver_results& b)
0291 {
0292 return !a.equal(b);
0293 }
0294
0295 private:
0296 typedef std::vector<basic_resolver_entry<InternetProtocol>> values_type;
0297 };
0298
0299 }
0300 }
0301 }
0302
0303 #include <boost/asio/detail/pop_options.hpp>
0304
0305 #endif