From 55b661d70f074368b0f2c8bbfaa33abc4ca212c3 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Fri, 11 Oct 2024 16:17:21 -0700 Subject: [PATCH] [wpinet] libuv: Change GetAddrInfo hints parameter to optional This is clearer than passing a pointer. --- wpinet/src/main/native/cpp/ParallelTcpConnector.cpp | 2 +- wpinet/src/main/native/cpp/uv/GetAddrInfo.cpp | 7 ++++--- wpinet/src/main/native/include/wpinet/uv/GetAddrInfo.h | 9 +++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/wpinet/src/main/native/cpp/ParallelTcpConnector.cpp b/wpinet/src/main/native/cpp/ParallelTcpConnector.cpp index 30663fc7325..1ee303e5222 100644 --- a/wpinet/src/main/native/cpp/ParallelTcpConnector.cpp +++ b/wpinet/src/main/native/cpp/ParallelTcpConnector.cpp @@ -198,7 +198,7 @@ void ParallelTcpConnector::Connect() { hints.ai_protocol = IPPROTO_TCP; hints.ai_flags = AI_NUMERICSERV | AI_ADDRCONFIG; uv::GetAddrInfo(m_loop, req, server.first, fmt::format("{}", server.second), - &hints); + hints); } } diff --git a/wpinet/src/main/native/cpp/uv/GetAddrInfo.cpp b/wpinet/src/main/native/cpp/uv/GetAddrInfo.cpp index 0b547e6ff52..93b36468f93 100644 --- a/wpinet/src/main/native/cpp/uv/GetAddrInfo.cpp +++ b/wpinet/src/main/native/cpp/uv/GetAddrInfo.cpp @@ -20,7 +20,7 @@ GetAddrInfoReq::GetAddrInfoReq() { void GetAddrInfo(Loop& loop, const std::shared_ptr& req, std::string_view node, std::string_view service, - const addrinfo* hints) { + std::optional hints) { if (loop.IsClosing()) { return; } @@ -39,7 +39,8 @@ void GetAddrInfo(Loop& loop, const std::shared_ptr& req, h.Release(); // this is always a one-shot }, node.empty() ? nullptr : nodeStr.c_str(), - service.empty() ? nullptr : serviceStr.c_str(), hints); + service.empty() ? nullptr : serviceStr.c_str(), + hints.has_value() ? &hints.value() : nullptr); if (err < 0) { loop.ReportError(err); } else { @@ -49,7 +50,7 @@ void GetAddrInfo(Loop& loop, const std::shared_ptr& req, void GetAddrInfo(Loop& loop, std::function callback, std::string_view node, std::string_view service, - const addrinfo* hints) { + std::optional hints) { auto req = std::make_shared(); req->resolved.connect(std::move(callback)); GetAddrInfo(loop, req, node, service, hints); diff --git a/wpinet/src/main/native/include/wpinet/uv/GetAddrInfo.h b/wpinet/src/main/native/include/wpinet/uv/GetAddrInfo.h index 59541104c7d..e4463376646 100644 --- a/wpinet/src/main/native/include/wpinet/uv/GetAddrInfo.h +++ b/wpinet/src/main/native/include/wpinet/uv/GetAddrInfo.h @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -53,7 +54,7 @@ class GetAddrInfoReq : public RequestImpl { */ void GetAddrInfo(Loop& loop, const std::shared_ptr& req, std::string_view node, std::string_view service = {}, - const addrinfo* hints = nullptr); + std::optional hints = {}); /** * Asynchronous getaddrinfo(3). HandleResolvedAddress() is called on the @@ -72,7 +73,7 @@ void GetAddrInfo(Loop& loop, const std::shared_ptr& req, inline void GetAddrInfo(const std::shared_ptr& loop, const std::shared_ptr& req, std::string_view node, std::string_view service = {}, - const addrinfo* hints = nullptr) { + std::optional hints = {}) { GetAddrInfo(*loop, req, node, service, hints); } @@ -92,7 +93,7 @@ inline void GetAddrInfo(const std::shared_ptr& loop, */ void GetAddrInfo(Loop& loop, std::function callback, std::string_view node, std::string_view service = {}, - const addrinfo* hints = nullptr); + std::optional hints = {}); /** * Asynchronous getaddrinfo(3). The callback is called when the resolution @@ -111,7 +112,7 @@ void GetAddrInfo(Loop& loop, std::function callback, inline void GetAddrInfo(const std::shared_ptr& loop, std::function callback, std::string_view node, std::string_view service = {}, - const addrinfo* hints = nullptr) { + std::optional hints = {}) { GetAddrInfo(*loop, std::move(callback), node, service, hints); }