[wpinet] libuv: Change GetAddrInfo hints parameter to optional (#7196)

This is clearer than passing a pointer.
This commit is contained in:
Peter Johnson
2024-10-11 16:42:42 -07:00
committed by GitHub
parent a621cebbd6
commit 768fa5f973
3 changed files with 10 additions and 8 deletions

View File

@@ -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);
}
}

View File

@@ -20,7 +20,7 @@ GetAddrInfoReq::GetAddrInfoReq() {
void GetAddrInfo(Loop& loop, const std::shared_ptr<GetAddrInfoReq>& req,
std::string_view node, std::string_view service,
const addrinfo* hints) {
std::optional<addrinfo> hints) {
if (loop.IsClosing()) {
return;
}
@@ -39,7 +39,8 @@ void GetAddrInfo(Loop& loop, const std::shared_ptr<GetAddrInfoReq>& 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<GetAddrInfoReq>& req,
void GetAddrInfo(Loop& loop, std::function<void(const addrinfo&)> callback,
std::string_view node, std::string_view service,
const addrinfo* hints) {
std::optional<addrinfo> hints) {
auto req = std::make_shared<GetAddrInfoReq>();
req->resolved.connect(std::move(callback));
GetAddrInfo(loop, req, node, service, hints);

View File

@@ -9,6 +9,7 @@
#include <functional>
#include <memory>
#include <optional>
#include <string_view>
#include <utility>
@@ -53,7 +54,7 @@ class GetAddrInfoReq : public RequestImpl<GetAddrInfoReq, uv_getaddrinfo_t> {
*/
void GetAddrInfo(Loop& loop, const std::shared_ptr<GetAddrInfoReq>& req,
std::string_view node, std::string_view service = {},
const addrinfo* hints = nullptr);
std::optional<addrinfo> hints = {});
/**
* Asynchronous getaddrinfo(3). HandleResolvedAddress() is called on the
@@ -72,7 +73,7 @@ void GetAddrInfo(Loop& loop, const std::shared_ptr<GetAddrInfoReq>& req,
inline void GetAddrInfo(const std::shared_ptr<Loop>& loop,
const std::shared_ptr<GetAddrInfoReq>& req,
std::string_view node, std::string_view service = {},
const addrinfo* hints = nullptr) {
std::optional<addrinfo> hints = {}) {
GetAddrInfo(*loop, req, node, service, hints);
}
@@ -92,7 +93,7 @@ inline void GetAddrInfo(const std::shared_ptr<Loop>& loop,
*/
void GetAddrInfo(Loop& loop, std::function<void(const addrinfo&)> callback,
std::string_view node, std::string_view service = {},
const addrinfo* hints = nullptr);
std::optional<addrinfo> hints = {});
/**
* Asynchronous getaddrinfo(3). The callback is called when the resolution
@@ -111,7 +112,7 @@ void GetAddrInfo(Loop& loop, std::function<void(const addrinfo&)> callback,
inline void GetAddrInfo(const std::shared_ptr<Loop>& loop,
std::function<void(const addrinfo&)> callback,
std::string_view node, std::string_view service = {},
const addrinfo* hints = nullptr) {
std::optional<addrinfo> hints = {}) {
GetAddrInfo(*loop, std::move(callback), node, service, hints);
}