include/boost/corosio/resolver_results.hpp
100.0% Lines (52/52)
100.0% List of functions (26/26)
90.0% Branches (9/10)
Functions (26)
Function
Calls
Lines
Branches
Blocks
boost::corosio::resolver_entry::resolver_entry(boost::corosio::resolver_entry&&)
:33
2x
100.0%
–
100.0%
boost::corosio::resolver_entry::~resolver_entry()
:33
54x
100.0%
–
100.0%
boost::corosio::resolver_entry::resolver_entry(boost::corosio::endpoint, std::__1::basic_string_view<char, std::__1::char_traits<char>>, std::__1::basic_string_view<char, std::__1::char_traits<char>>)
:49
52x
100.0%
50.0%
100.0%
boost::corosio::resolver_entry::get_endpoint() const
:57
7x
100.0%
–
100.0%
boost::corosio::resolver_entry::operator boost::corosio::endpoint() const
:63
1x
100.0%
–
100.0%
boost::corosio::resolver_entry::host_name() const
:69
2x
100.0%
–
100.0%
boost::corosio::resolver_entry::service_name() const
:75
2x
100.0%
–
100.0%
boost::corosio::resolver_results::operator=(boost::corosio::resolver_results&&)
:91
56x
100.0%
–
100.0%
boost::corosio::resolver_results::resolver_results(boost::corosio::resolver_results&&)
:91
72x
100.0%
–
100.0%
boost::corosio::resolver_results::~resolver_results()
:91
266x
100.0%
–
100.0%
boost::corosio::resolver_results::resolver_results()
:120
160x
100.0%
–
100.0%
boost::corosio::resolver_results::resolver_results(std::__1::vector<boost::corosio::resolver_entry, std::__1::allocator<boost::corosio::resolver_entry>>)
:126
34x
100.0%
–
100.0%
boost::corosio::resolver_results::size() const
:133
11x
100.0%
100.0%
100.0%
boost::corosio::resolver_results::empty() const
:139
11x
100.0%
100.0%
100.0%
boost::corosio::resolver_results::begin() const
:145
9x
100.0%
100.0%
100.0%
boost::corosio::resolver_results::end() const
:153
6x
100.0%
100.0%
100.0%
boost::corosio::resolver_results::cbegin() const
:161
1x
100.0%
–
100.0%
boost::corosio::resolver_results::cend() const
:167
3x
100.0%
–
100.0%
boost::corosio::resolver_results::swap(boost::corosio::resolver_results&)
:173
1x
100.0%
–
100.0%
boost::corosio::reverse_resolver_result::operator=(boost::corosio::reverse_resolver_result&&)
:202
13x
100.0%
–
100.0%
boost::corosio::reverse_resolver_result::reverse_resolver_result(boost::corosio::reverse_resolver_result&&)
:202
40x
100.0%
–
100.0%
boost::corosio::reverse_resolver_result::~reverse_resolver_result()
:202
86x
100.0%
–
100.0%
boost::corosio::reverse_resolver_result::reverse_resolver_result()
:210
28x
100.0%
–
100.0%
boost::corosio::reverse_resolver_result::reverse_resolver_result(boost::corosio::endpoint, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>)
:218
18x
100.0%
–
100.0%
boost::corosio::reverse_resolver_result::host_name() const
:233
4x
100.0%
–
100.0%
boost::corosio::reverse_resolver_result::service_name() const
:239
4x
100.0%
–
100.0%
| Line | Branch | TLA | Hits | Source Code |
|---|---|---|---|---|
| 1 | // | |||
| 2 | // Copyright (c) 2025 Vinnie Falco ([email protected]) | |||
| 3 | // | |||
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |||
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |||
| 6 | // | |||
| 7 | // Official repository: https://github.com/cppalliance/corosio | |||
| 8 | // | |||
| 9 | ||||
| 10 | #ifndef BOOST_COROSIO_RESOLVER_RESULTS_HPP | |||
| 11 | #define BOOST_COROSIO_RESOLVER_RESULTS_HPP | |||
| 12 | ||||
| 13 | #include <boost/corosio/detail/config.hpp> | |||
| 14 | #include <boost/corosio/endpoint.hpp> | |||
| 15 | ||||
| 16 | #include <cstddef> | |||
| 17 | #include <memory> | |||
| 18 | #include <string> | |||
| 19 | #include <string_view> | |||
| 20 | #include <vector> | |||
| 21 | ||||
| 22 | namespace boost::corosio { | |||
| 23 | ||||
| 24 | /** A single entry produced by a resolver. | |||
| 25 | ||||
| 26 | This class represents one resolved endpoint along with | |||
| 27 | the host and service names used in the query. | |||
| 28 | ||||
| 29 | @par Thread Safety | |||
| 30 | Distinct objects: Safe.@n | |||
| 31 | Shared objects: Safe. | |||
| 32 | */ | |||
| 33 | class resolver_entry | |||
| 34 | { | |||
| 35 | endpoint ep_; | |||
| 36 | std::string host_name_; | |||
| 37 | std::string service_name_; | |||
| 38 | ||||
| 39 | public: | |||
| 40 | /// Construct a default empty entry. | |||
| 41 | resolver_entry() = default; | |||
| 42 | ||||
| 43 | /** Construct with endpoint, host name, and service name. | |||
| 44 | ||||
| 45 | @param ep The resolved endpoint. | |||
| 46 | @param host The host name from the query. | |||
| 47 | @param service The service name from the query. | |||
| 48 | */ | |||
| 49 | 52x | resolver_entry(endpoint ep, std::string_view host, std::string_view service) | ||
| 50 | 26x | : ep_(ep) | ||
| 51 | 26x | , host_name_(host) | ||
| 52 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26x | , service_name_(service) | |
| 53 | 26x | { | ||
| 54 | 52x | } | ||
| 55 | ||||
| 56 | /// Return the resolved endpoint. | |||
| 57 | 7x | endpoint get_endpoint() const noexcept | ||
| 58 | { | |||
| 59 | 7x | return ep_; | ||
| 60 | } | |||
| 61 | ||||
| 62 | /// Convert to endpoint. | |||
| 63 | 1x | operator endpoint() const noexcept | ||
| 64 | { | |||
| 65 | 1x | return ep_; | ||
| 66 | } | |||
| 67 | ||||
| 68 | /// Return the host name from the query. | |||
| 69 | 2x | std::string const& host_name() const noexcept | ||
| 70 | { | |||
| 71 | 2x | return host_name_; | ||
| 72 | } | |||
| 73 | ||||
| 74 | /// Return the service name from the query. | |||
| 75 | 2x | std::string const& service_name() const noexcept | ||
| 76 | { | |||
| 77 | 2x | return service_name_; | ||
| 78 | } | |||
| 79 | }; | |||
| 80 | ||||
| 81 | /** A range of entries produced by a resolver. | |||
| 82 | ||||
| 83 | This class holds the results of a DNS resolution query. | |||
| 84 | It provides a range interface for iterating over the | |||
| 85 | resolved endpoints. | |||
| 86 | ||||
| 87 | @par Thread Safety | |||
| 88 | Distinct objects: Safe.@n | |||
| 89 | Shared objects: Safe (immutable after construction). | |||
| 90 | */ | |||
| 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 | 160x | resolver_results() = default; | ||
| 121 | ||||
| 122 | /** Construct from a vector of entries. | |||
| 123 | ||||
| 124 | @param entries The resolved entries. | |||
| 125 | */ | |||
| 126 | 34x | explicit resolver_results(std::vector<resolver_entry> entries) | ||
| 127 | 17x | : entries_( | ||
| 128 | 17x | std::make_shared<std::vector<resolver_entry>>(std::move(entries))) | ||
| 129 | 17x | { | ||
| 130 | 34x | } | ||
| 131 | ||||
| 132 | /// Return the number of entries. | |||
| 133 | 11x | size_type size() const noexcept | ||
| 134 | { | |||
| 135 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 time.
|
11x | return entries_ ? entries_->size() : 0; | |
| 136 | } | |||
| 137 | ||||
| 138 | /// Check if the results are empty. | |||
| 139 | 11x | bool empty() const noexcept | ||
| 140 | { | |||
| 141 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9 times.
|
11x | return !entries_ || entries_->empty(); | |
| 142 | } | |||
| 143 | ||||
| 144 | /// Return an iterator to the first entry. | |||
| 145 | 9x | const_iterator begin() const noexcept | ||
| 146 | { | |||
| 147 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 time.
|
9x | if (entries_) | |
| 148 | 8x | return entries_->begin(); | ||
| 149 | 1x | return std::vector<resolver_entry>::const_iterator(); | ||
| 150 | 9x | } | ||
| 151 | ||||
| 152 | /// Return an iterator past the last entry. | |||
| 153 | 6x | const_iterator end() const noexcept | ||
| 154 | { | |||
| 155 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 time.
|
6x | if (entries_) | |
| 156 | 5x | return entries_->end(); | ||
| 157 | 1x | return std::vector<resolver_entry>::const_iterator(); | ||
| 158 | 6x | } | ||
| 159 | ||||
| 160 | /// Return an iterator to the first entry. | |||
| 161 | 1x | const_iterator cbegin() const noexcept | ||
| 162 | { | |||
| 163 | 1x | return begin(); | ||
| 164 | } | |||
| 165 | ||||
| 166 | /// Return an iterator past the last entry. | |||
| 167 | 3x | const_iterator cend() const noexcept | ||
| 168 | { | |||
| 169 | 3x | return end(); | ||
| 170 | } | |||
| 171 | ||||
| 172 | /// Swap with another results object. | |||
| 173 | 1x | void swap(resolver_results& other) noexcept | ||
| 174 | { | |||
| 175 | 1x | entries_.swap(other.entries_); | ||
| 176 | 1x | } | ||
| 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 | }; | |||
| 192 | ||||
| 193 | /** The result of a reverse DNS resolution. | |||
| 194 | ||||
| 195 | This class holds the result of resolving an endpoint | |||
| 196 | into a hostname and service name. | |||
| 197 | ||||
| 198 | @par Thread Safety | |||
| 199 | Distinct objects: Safe.@n | |||
| 200 | Shared objects: Safe. | |||
| 201 | */ | |||
| 202 | class reverse_resolver_result | |||
| 203 | { | |||
| 204 | corosio::endpoint ep_; | |||
| 205 | std::string host_; | |||
| 206 | std::string service_; | |||
| 207 | ||||
| 208 | public: | |||
| 209 | /// Construct a default empty result. | |||
| 210 | 28x | reverse_resolver_result() = default; | ||
| 211 | ||||
| 212 | /** Construct with endpoint, host name, and service name. | |||
| 213 | ||||
| 214 | @param ep The endpoint that was resolved. | |||
| 215 | @param host The resolved host name. | |||
| 216 | @param service The resolved service name. | |||
| 217 | */ | |||
| 218 | 18x | reverse_resolver_result( | ||
| 219 | corosio::endpoint ep, std::string host, std::string service) | |||
| 220 | 9x | : ep_(ep) | ||
| 221 | 9x | , host_(std::move(host)) | ||
| 222 | 9x | , service_(std::move(service)) | ||
| 223 | 9x | { | ||
| 224 | 18x | } | ||
| 225 | ||||
| 226 | /// Return the endpoint that was resolved. | |||
| 227 | corosio::endpoint endpoint() const noexcept | |||
| 228 | { | |||
| 229 | return ep_; | |||
| 230 | } | |||
| 231 | ||||
| 232 | /// Return the resolved host name. | |||
| 233 | 4x | std::string const& host_name() const noexcept | ||
| 234 | { | |||
| 235 | 4x | return host_; | ||
| 236 | } | |||
| 237 | ||||
| 238 | /// Return the resolved service name. | |||
| 239 | 4x | std::string const& service_name() const noexcept | ||
| 240 | { | |||
| 241 | 4x | return service_; | ||
| 242 | } | |||
| 243 | }; | |||
| 244 | ||||
| 245 | } // namespace boost::corosio | |||
| 246 | ||||
| 247 | #endif | |||
| 248 |