This commit is contained in:
zhangxiaoyu.york 2024-09-04 19:40:43 +08:00
parent 1f6a0726d9
commit 49a31df3da
2 changed files with 16 additions and 1 deletions

View File

@ -110,7 +110,15 @@ static bool dns_resolve(std::string const& target,
#endif #endif
return false; return false;
} }
target_parts.push_back(target.substr(0, rindex));
std::string host(target.substr(0,rindex));
// check target is '[ipv6]:port'
if(!ipv4 && !host.empty() && host[0] == '[' && host[host.size()-1] == ']') {
endpoints.emplace_back(target);
return true;
}
target_parts.push_back(host);
target_parts.push_back(target.substr(rindex + 1)); target_parts.push_back(target.substr(rindex + 1));
} }

View File

@ -9,6 +9,9 @@ static const std::string etcd_v4_url =
etcdv3::detail::resolve_etcd_endpoints("http://127.0.0.1:2379"); etcdv3::detail::resolve_etcd_endpoints("http://127.0.0.1:2379");
static const std::string etcd_v6_url = static const std::string etcd_v6_url =
etcdv3::detail::resolve_etcd_endpoints("http://::1:2379"); etcdv3::detail::resolve_etcd_endpoints("http://::1:2379");
// http://[ipv6]:port url
static const std::string etcd_ipv6_url =
etcdv3::detail::resolve_etcd_endpoints("http://[::1]:2379");
TEST_CASE("test ipv4 connection") { TEST_CASE("test ipv4 connection") {
std::cout << "ipv4 endpoints: " << etcd_v4_url << std::endl; std::cout << "ipv4 endpoints: " << etcd_v4_url << std::endl;
@ -20,4 +23,8 @@ TEST_CASE("test ipv6 connection") {
std::cout << "ipv6 endpoints: " << etcd_v6_url << std::endl; std::cout << "ipv6 endpoints: " << etcd_v6_url << std::endl;
etcd::Client etcd(etcd_v6_url); etcd::Client etcd(etcd_v6_url);
REQUIRE(etcd.head().get().is_ok()); REQUIRE(etcd.head().get().is_ok());
std::cout << "ipv6 endpoints: " << etcd_ipv6_url << std::endl;
etcd::Client etcd1(etcd_ipv6_url);
REQUIRE(etcd1.head().get().is_ok());
} }