Skip to content

Commit

Permalink
[wpinet] libuv: Change GetAddrInfo hints parameter to optional
Browse files Browse the repository at this point in the history
This is clearer than passing a pointer.
  • Loading branch information
PeterJohnson committed Oct 11, 2024
1 parent 96f0b24 commit 55b661d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion wpinet/src/main/native/cpp/ParallelTcpConnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
7 changes: 4 additions & 3 deletions wpinet/src/main/native/cpp/uv/GetAddrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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 {
Expand All @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions wpinet/src/main/native/include/wpinet/uv/GetAddrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <functional>
#include <memory>
#include <optional>
#include <string_view>
#include <utility>

Expand Down Expand Up @@ -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
Expand All @@ -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);
}

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

Expand Down

0 comments on commit 55b661d

Please sign in to comment.