diff options
Diffstat (limited to 'boost/asio/ip/basic_resolver_iterator.hpp')
-rw-r--r-- | boost/asio/ip/basic_resolver_iterator.hpp | 128 |
1 files changed, 30 insertions, 98 deletions
diff --git a/boost/asio/ip/basic_resolver_iterator.hpp b/boost/asio/ip/basic_resolver_iterator.hpp index b7deb77364..6571fdd982 100644 --- a/boost/asio/ip/basic_resolver_iterator.hpp +++ b/boost/asio/ip/basic_resolver_iterator.hpp @@ -21,7 +21,7 @@ #include <iterator> #include <string> #include <vector> -#include <boost/asio/detail/shared_ptr.hpp> +#include <boost/asio/detail/memory.hpp> #include <boost/asio/detail/socket_ops.hpp> #include <boost/asio/detail/socket_types.hpp> #include <boost/asio/ip/basic_resolver_entry.hpp> @@ -73,114 +73,45 @@ public: { } - /// Create an iterator from an addrinfo list returned by getaddrinfo. - static basic_resolver_iterator create( - boost::asio::detail::addrinfo_type* address_info, - const std::string& host_name, const std::string& service_name) + /// Copy constructor. + basic_resolver_iterator(const basic_resolver_iterator& other) + : values_(other.values_), + index_(other.index_) { - basic_resolver_iterator iter; - if (!address_info) - return iter; - - std::string actual_host_name = host_name; - if (address_info->ai_canonname) - actual_host_name = address_info->ai_canonname; - - iter.values_.reset(new values_type); - - while (address_info) - { - if (address_info->ai_family == BOOST_ASIO_OS_DEF(AF_INET) - || address_info->ai_family == BOOST_ASIO_OS_DEF(AF_INET6)) - { - using namespace std; // For memcpy. - typename InternetProtocol::endpoint endpoint; - endpoint.resize(static_cast<std::size_t>(address_info->ai_addrlen)); - memcpy(endpoint.data(), address_info->ai_addr, - address_info->ai_addrlen); - iter.values_->push_back( - basic_resolver_entry<InternetProtocol>(endpoint, - actual_host_name, service_name)); - } - address_info = address_info->ai_next; - } - - return iter; } - /// Create an iterator from an endpoint, host name and service name. - static basic_resolver_iterator create( - const typename InternetProtocol::endpoint& endpoint, - const std::string& host_name, const std::string& service_name) +#if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) + /// Move constructor. + basic_resolver_iterator(basic_resolver_iterator&& other) + : values_(BOOST_ASIO_MOVE_CAST(values_ptr_type)(other.values_)), + index_(other.index_) { - basic_resolver_iterator iter; - iter.values_.reset(new values_type); - iter.values_->push_back( - basic_resolver_entry<InternetProtocol>( - endpoint, host_name, service_name)); - return iter; + other.index_ = 0; } +#endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) - /// Create an iterator from a sequence of endpoints, host and service name. - template <typename EndpointIterator> - static basic_resolver_iterator create( - EndpointIterator begin, EndpointIterator end, - const std::string& host_name, const std::string& service_name) + /// Assignment operator. + basic_resolver_iterator& operator=(const basic_resolver_iterator& other) { - basic_resolver_iterator iter; - if (begin != end) - { - iter.values_.reset(new values_type); - for (EndpointIterator ep_iter = begin; ep_iter != end; ++ep_iter) - { - iter.values_->push_back( - basic_resolver_entry<InternetProtocol>( - *ep_iter, host_name, service_name)); - } - } - return iter; + values_ = other.values_; + index_ = other.index_; + return *this; } -#if defined(BOOST_ASIO_WINDOWS_RUNTIME) - /// Create an iterator from a Windows Runtime list of EndpointPair objects. - static basic_resolver_iterator create( - Windows::Foundation::Collections::IVectorView< - Windows::Networking::EndpointPair^>^ endpoints, - const boost::asio::detail::addrinfo_type& hints, - const std::string& host_name, const std::string& service_name) +#if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) + /// Move-assignment operator. + basic_resolver_iterator& operator=(basic_resolver_iterator&& other) { - basic_resolver_iterator iter; - if (endpoints->Size) + if (this != &other) { - iter.values_.reset(new values_type); - for (unsigned int i = 0; i < endpoints->Size; ++i) - { - auto pair = endpoints->GetAt(i); - - if (hints.ai_family == BOOST_ASIO_OS_DEF(AF_INET) - && pair->RemoteHostName->Type - != Windows::Networking::HostNameType::Ipv4) - continue; - - if (hints.ai_family == BOOST_ASIO_OS_DEF(AF_INET6) - && pair->RemoteHostName->Type - != Windows::Networking::HostNameType::Ipv6) - continue; - - iter.values_->push_back( - basic_resolver_entry<InternetProtocol>( - typename InternetProtocol::endpoint( - ip::address::from_string( - boost::asio::detail::winrt_utils::string( - pair->RemoteHostName->CanonicalName)), - boost::asio::detail::winrt_utils::integer( - pair->RemoteServiceName)), - host_name, service_name)); - } + values_ = BOOST_ASIO_MOVE_CAST(values_ptr_type)(other.values_); + index_ = other.index_; + other.index_ = 0; } - return iter; + + return *this; } -#endif // defined(BOOST_ASIO_WINDOWS_RUNTIME) +#endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) /// Dereference an iterator. const basic_resolver_entry<InternetProtocol>& operator*() const @@ -223,7 +154,7 @@ public: return !a.equal(b); } -private: +protected: void increment() { if (++index_ == values_->size()) @@ -249,7 +180,8 @@ private: } typedef std::vector<basic_resolver_entry<InternetProtocol> > values_type; - boost::asio::detail::shared_ptr<values_type> values_; + typedef boost::asio::detail::shared_ptr<values_type> values_ptr_type; + values_ptr_type values_; std::size_t index_; }; |