|
1 | 1 | // |
2 | 2 | // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com) |
| 3 | +// Copyright (c) 2026 Michael Vandeberg |
3 | 4 | // |
4 | 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
5 | 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
|
13 | 14 | #include <boost/corosio/detail/config.hpp> |
14 | 15 | #include <boost/corosio/endpoint.hpp> |
15 | 16 |
|
16 | | -#include <cstddef> |
17 | | -#include <memory> |
18 | 17 | #include <string> |
19 | 18 | #include <string_view> |
20 | 19 | #include <vector> |
@@ -80,115 +79,21 @@ class resolver_entry |
80 | 79 |
|
81 | 80 | /** A range of entries produced by a resolver. |
82 | 81 |
|
83 | | - This class holds the results of a DNS resolution query. |
84 | | - It provides a range interface for iterating over the |
85 | | - resolved endpoints. |
| 82 | + This is an alias for `std::vector<resolver_entry>`: a contiguous, |
| 83 | + owning range of the endpoints resolved by a query. It supports the |
| 84 | + full `std::vector` interface (iteration, `size()`, `empty()`, etc.). |
| 85 | +
|
| 86 | + @note Copying a `resolver_results` deep-copies every entry, and each |
| 87 | + entry owns two `std::string`s (the host and service names). When you |
| 88 | + want to hand a result to a sink that takes the range by value — such |
| 89 | + as `corosio::connect` — pass an rvalue (`std::move(results)`) or use |
| 90 | + the iterator-based `connect` overloads to avoid the copy. |
86 | 91 |
|
87 | 92 | @par Thread Safety |
88 | 93 | Distinct objects: Safe.@n |
89 | | - Shared objects: Safe (immutable after construction). |
| 94 | + Shared objects: Unsafe. |
90 | 95 | */ |
91 | | -class resolver_results |
92 | | -{ |
93 | | -public: |
94 | | - /// The entry type. |
95 | | - using value_type = resolver_entry; |
96 | | - |
97 | | - /// Const reference to an entry. |
98 | | - using const_reference = value_type const&; |
99 | | - |
100 | | - /// Reference to an entry (always const). |
101 | | - using reference = const_reference; |
102 | | - |
103 | | - /// Const iterator over entries. |
104 | | - using const_iterator = std::vector<resolver_entry>::const_iterator; |
105 | | - |
106 | | - /// Iterator over entries (always const). |
107 | | - using iterator = const_iterator; |
108 | | - |
109 | | - /// Signed difference type. |
110 | | - using difference_type = std::ptrdiff_t; |
111 | | - |
112 | | - /// Unsigned size type. |
113 | | - using size_type = std::size_t; |
114 | | - |
115 | | -private: |
116 | | - std::shared_ptr<std::vector<resolver_entry>> entries_; |
117 | | - |
118 | | -public: |
119 | | - /// Construct an empty results range. |
120 | | - resolver_results() = default; |
121 | | - |
122 | | - /** Construct from a vector of entries. |
123 | | -
|
124 | | - @param entries The resolved entries. |
125 | | - */ |
126 | | - explicit resolver_results(std::vector<resolver_entry> entries) |
127 | | - : entries_( |
128 | | - std::make_shared<std::vector<resolver_entry>>(std::move(entries))) |
129 | | - { |
130 | | - } |
131 | | - |
132 | | - /// Return the number of entries. |
133 | | - size_type size() const noexcept |
134 | | - { |
135 | | - return entries_ ? entries_->size() : 0; |
136 | | - } |
137 | | - |
138 | | - /// Check if the results are empty. |
139 | | - bool empty() const noexcept |
140 | | - { |
141 | | - return !entries_ || entries_->empty(); |
142 | | - } |
143 | | - |
144 | | - /// Return an iterator to the first entry. |
145 | | - const_iterator begin() const noexcept |
146 | | - { |
147 | | - if (entries_) |
148 | | - return entries_->begin(); |
149 | | - return std::vector<resolver_entry>::const_iterator(); |
150 | | - } |
151 | | - |
152 | | - /// Return an iterator past the last entry. |
153 | | - const_iterator end() const noexcept |
154 | | - { |
155 | | - if (entries_) |
156 | | - return entries_->end(); |
157 | | - return std::vector<resolver_entry>::const_iterator(); |
158 | | - } |
159 | | - |
160 | | - /// Return an iterator to the first entry. |
161 | | - const_iterator cbegin() const noexcept |
162 | | - { |
163 | | - return begin(); |
164 | | - } |
165 | | - |
166 | | - /// Return an iterator past the last entry. |
167 | | - const_iterator cend() const noexcept |
168 | | - { |
169 | | - return end(); |
170 | | - } |
171 | | - |
172 | | - /// Swap with another results object. |
173 | | - void swap(resolver_results& other) noexcept |
174 | | - { |
175 | | - entries_.swap(other.entries_); |
176 | | - } |
177 | | - |
178 | | - /// Test for equality. |
179 | | - friend bool |
180 | | - operator==(resolver_results const& a, resolver_results const& b) noexcept |
181 | | - { |
182 | | - return a.entries_ == b.entries_; |
183 | | - } |
184 | | - |
185 | | - /// Test for inequality. |
186 | | - friend bool |
187 | | - operator!=(resolver_results const& a, resolver_results const& b) noexcept |
188 | | - { |
189 | | - return !(a == b); |
190 | | - } |
191 | | -}; |
| 96 | +using resolver_results = std::vector<resolver_entry>; |
192 | 97 |
|
193 | 98 | /** The result of a reverse DNS resolution. |
194 | 99 |
|
|
0 commit comments