include/boost/corosio/resolver_results.hpp
100.0% Lines (23/23)
100.0% List of functions (9/9)
100.0% Branches (2/2)
Functions (9)
Function
Calls
Lines
Branches
Blocks
boost::corosio::resolver_entry::resolver_entry(boost::corosio::endpoint, std::basic_string_view<char, std::char_traits<char> >, std::basic_string_view<char, std::char_traits<char> >)
:48
27x
100.0%
100.0%
58.8%
boost::corosio::resolver_entry::get_endpoint() const
:56
7x
100.0%
–
100.0%
boost::corosio::resolver_entry::operator boost::corosio::endpoint() const
:62
1x
100.0%
–
100.0%
boost::corosio::resolver_entry::host_name[abi:cxx11]() const
:68
2x
100.0%
–
100.0%
boost::corosio::resolver_entry::service_name[abi:cxx11]() const
:74
2x
100.0%
–
100.0%
boost::corosio::reverse_resolver_result::reverse_resolver_result()
:115
19x
100.0%
–
100.0%
boost::corosio::reverse_resolver_result::reverse_resolver_result(boost::corosio::endpoint, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)
:123
11x
100.0%
–
100.0%
boost::corosio::reverse_resolver_result::host_name[abi:cxx11]() const
:138
5x
100.0%
–
100.0%
boost::corosio::reverse_resolver_result::service_name[abi:cxx11]() const
:144
4x
100.0%
–
100.0%
| Line | Branch | TLA | Hits | Source Code |
|---|---|---|---|---|
| 1 | // | |||
| 2 | // Copyright (c) 2025 Vinnie Falco ([email protected]) | |||
| 3 | // Copyright (c) 2026 Michael Vandeberg | |||
| 4 | // | |||
| 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |||
| 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |||
| 7 | // | |||
| 8 | // Official repository: https://github.com/cppalliance/corosio | |||
| 9 | // | |||
| 10 | ||||
| 11 | #ifndef BOOST_COROSIO_RESOLVER_RESULTS_HPP | |||
| 12 | #define BOOST_COROSIO_RESOLVER_RESULTS_HPP | |||
| 13 | ||||
| 14 | #include <boost/corosio/detail/config.hpp> | |||
| 15 | #include <boost/corosio/endpoint.hpp> | |||
| 16 | ||||
| 17 | #include <string> | |||
| 18 | #include <string_view> | |||
| 19 | #include <vector> | |||
| 20 | ||||
| 21 | namespace boost::corosio { | |||
| 22 | ||||
| 23 | /** A single entry produced by a resolver. | |||
| 24 | ||||
| 25 | This class represents one resolved endpoint along with | |||
| 26 | the host and service names used in the query. | |||
| 27 | ||||
| 28 | @par Thread Safety | |||
| 29 | Distinct objects: Safe.@n | |||
| 30 | Shared objects: Safe. | |||
| 31 | */ | |||
| 32 | class resolver_entry | |||
| 33 | { | |||
| 34 | endpoint ep_; | |||
| 35 | std::string host_name_; | |||
| 36 | std::string service_name_; | |||
| 37 | ||||
| 38 | public: | |||
| 39 | /// Construct a default empty entry. | |||
| 40 | resolver_entry() = default; | |||
| 41 | ||||
| 42 | /** Construct with endpoint, host name, and service name. | |||
| 43 | ||||
| 44 | @param ep The resolved endpoint. | |||
| 45 | @param host The host name from the query. | |||
| 46 | @param service The service name from the query. | |||
| 47 | */ | |||
| 48 | 27x | resolver_entry(endpoint ep, std::string_view host, std::string_view service) | ||
| 49 | 27x | : ep_(ep) | ||
| 50 |
1/1✓ Branch 4 → 5 taken 27 times.
|
54x | , host_name_(host) | |
| 51 |
1/1✓ Branch 8 → 9 taken 27 times.
|
54x | , service_name_(service) | |
| 52 | { | |||
| 53 | 27x | } | ||
| 54 | ||||
| 55 | /// Return the resolved endpoint. | |||
| 56 | 7x | endpoint get_endpoint() const noexcept | ||
| 57 | { | |||
| 58 | 7x | return ep_; | ||
| 59 | } | |||
| 60 | ||||
| 61 | /// Convert to endpoint. | |||
| 62 | 1x | operator endpoint() const noexcept | ||
| 63 | { | |||
| 64 | 1x | return ep_; | ||
| 65 | } | |||
| 66 | ||||
| 67 | /// Return the host name from the query. | |||
| 68 | 2x | std::string const& host_name() const noexcept | ||
| 69 | { | |||
| 70 | 2x | return host_name_; | ||
| 71 | } | |||
| 72 | ||||
| 73 | /// Return the service name from the query. | |||
| 74 | 2x | std::string const& service_name() const noexcept | ||
| 75 | { | |||
| 76 | 2x | return service_name_; | ||
| 77 | } | |||
| 78 | }; | |||
| 79 | ||||
| 80 | /** A range of entries produced by a resolver. | |||
| 81 | ||||
| 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. | |||
| 91 | ||||
| 92 | @par Thread Safety | |||
| 93 | Distinct objects: Safe.@n | |||
| 94 | Shared objects: Unsafe. | |||
| 95 | */ | |||
| 96 | using resolver_results = std::vector<resolver_entry>; | |||
| 97 | ||||
| 98 | /** The result of a reverse DNS resolution. | |||
| 99 | ||||
| 100 | This class holds the result of resolving an endpoint | |||
| 101 | into a hostname and service name. | |||
| 102 | ||||
| 103 | @par Thread Safety | |||
| 104 | Distinct objects: Safe.@n | |||
| 105 | Shared objects: Safe. | |||
| 106 | */ | |||
| 107 | class reverse_resolver_result | |||
| 108 | { | |||
| 109 | corosio::endpoint ep_; | |||
| 110 | std::string host_; | |||
| 111 | std::string service_; | |||
| 112 | ||||
| 113 | public: | |||
| 114 | /// Construct a default empty result. | |||
| 115 | 19x | reverse_resolver_result() = default; | ||
| 116 | ||||
| 117 | /** Construct with endpoint, host name, and service name. | |||
| 118 | ||||
| 119 | @param ep The endpoint that was resolved. | |||
| 120 | @param host The resolved host name. | |||
| 121 | @param service The resolved service name. | |||
| 122 | */ | |||
| 123 | 11x | reverse_resolver_result( | ||
| 124 | corosio::endpoint ep, std::string host, std::string service) | |||
| 125 | 11x | : ep_(ep) | ||
| 126 | 11x | , host_(std::move(host)) | ||
| 127 | 11x | , service_(std::move(service)) | ||
| 128 | { | |||
| 129 | 11x | } | ||
| 130 | ||||
| 131 | /// Return the endpoint that was resolved. | |||
| 132 | corosio::endpoint endpoint() const noexcept | |||
| 133 | { | |||
| 134 | return ep_; | |||
| 135 | } | |||
| 136 | ||||
| 137 | /// Return the resolved host name. | |||
| 138 | 5x | std::string const& host_name() const noexcept | ||
| 139 | { | |||
| 140 | 5x | return host_; | ||
| 141 | } | |||
| 142 | ||||
| 143 | /// Return the resolved service name. | |||
| 144 | 4x | std::string const& service_name() const noexcept | ||
| 145 | { | |||
| 146 | 4x | return service_; | ||
| 147 | } | |||
| 148 | }; | |||
| 149 | ||||
| 150 | } // namespace boost::corosio | |||
| 151 | ||||
| 152 | #endif | |||
| 153 |