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