0.00% Lines (0/0) 0.00% Functions (0/0)
TLA Baseline Branch
Line Hits Code Line Hits Code
1 - //  
2 - // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com)  
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 - */  
DCB 48 - 27 resolver_entry(endpoint ep, std::string_view host, std::string_view service)  
DCB 49 - 27 : ep_(ep)  
DCB 50 - 54 , host_name_(host)  
DCB 51 - 54 , service_name_(service)  
52 - {  
DCB 53 - 27 }  
54 -  
55 - /// Return the resolved endpoint.  
DCB 56 - 10 endpoint get_endpoint() const noexcept  
57 - {  
DCB 58 - 10 return ep_;  
59 - }  
60 -  
61 - /// Convert to endpoint.  
DCB 62 - 1 operator endpoint() const noexcept  
63 - {  
DCB 64 - 1 return ep_;  
65 - }  
66 -  
67 - /// Return the host name from the query.  
DCB 68 - 2 std::string const& host_name() const noexcept  
69 - {  
DCB 70 - 2 return host_name_;  
71 - }  
72 -  
73 - /// Return the service name from the query.  
DCB 74 - 2 std::string const& service_name() const noexcept  
75 - {  
DCB 76 - 2 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.  
DCB 115 - 25 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 - */  
DCB 123 - 10 reverse_resolver_result(  
124 - corosio::endpoint ep, std::string host, std::string service)  
DCB 125 - 10 : ep_(ep)  
DCB 126 - 10 , host_(std::move(host))  
DCB 127 - 10 , service_(std::move(service))  
128 - {  
DCB 129 - 10 }  
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.  
DCB 138 - 5 std::string const& host_name() const noexcept  
139 - {  
DCB 140 - 5 return host_;  
141 - }  
142 -  
143 - /// Return the resolved service name.  
DCB 144 - 4 std::string const& service_name() const noexcept  
145 - {  
DCB 146 - 4 return service_;  
147 - }  
148 - };  
149 -  
150 - } // namespace boost::corosio  
151 -  
152 - #endif