MySQL 9.7.0
Source Code Documentation
resolver_net_ts.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2026, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25#ifndef ROUTER_SRC_HARNESS_SRC_RESOLVER_RESOLVER_NET_TS_H_
26#define ROUTER_SRC_HARNESS_SRC_RESOLVER_RESOLVER_NET_TS_H_
27
28#include <string>
29#include <utility>
30
34
35namespace mysql_harness {
36namespace resolver {
37
39 public:
40 ResolveHostResult resolve_host(const std::string &hostname,
41 CachePolicy /*cache_policy*/) override {
42 // Create io_context only for resolution. Net-ts just gets
43 // the correct impl of 'getaddrinfo'. The context is not used
44 // to do any async name-resolution.
45 static net::io_context s_context;
46 net::ip::tcp::resolver resolver(s_context);
47
48 auto resolve_result = resolver.resolve(hostname, {});
49
50 if (!resolve_result) {
51 if (resolve_result.error().category() == net::ip::resolver_category() &&
52 resolve_result.error().value() == EAI_NONAME) {
54 }
55
56 return stdx::unexpected(resolve_result.error());
57 }
58
60 result.addresses.reserve(resolve_result.value().size());
61 for (const auto &entry : *resolve_result) {
62 auto address = entry.endpoint().address();
63 if (address.is_v4() || address.is_v6()) {
64 result.addresses.emplace_back(std::move(address));
65 }
66 }
67
68 return result;
69 }
70};
71
72} // namespace resolver
73} // namespace mysql_harness
74
75#endif /* ROUTER_SRC_HARNESS_SRC_RESOLVER_RESOLVER_NET_TS_H_ */
Definition: resolver_net_ts.h:38
ResolveHostResult resolve_host(const std::string &hostname, CachePolicy) override
Definition: resolver_net_ts.h:40
Definition: io_context.h:61
Definition: internet.h:608
stdx::expected< results_type, error_type > resolve(const std::string &host_name, const std::string &service_name, flags f)
Definition: internet.h:618
Definition: expected.h:286
@ NotFound
Deterministic negative outcome (NXDOMAIN, NODATA).
CachePolicy
Definition: common.h:40
HARNESS_EXPORT std::error_code make_error_code(ErrcResolveResult) noexcept
Definition: error_code.cc:56
Definition: common.h:44
const std::error_category & resolver_category() noexcept
Definition: resolver.h:113
unexpected(E) -> unexpected< E >
struct result result
Definition: result.h:34
Definition: completion_hash.h:35
Definition: result.h:30