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