Files
allwpilib/wpiutil/src/main/native/cpp/uv/GetNameInfo.cpp
Peter Johnson b2c3b2dd8e Use std::string_view and fmtlib across all libraries (#3402)
- Twine, StringRef, Format, and NativeFormatting have been removed
- Logging now uses fmtlib style formatting
- Nearly all uses of wpi::outs/errs have been replaced with fmt::print() or
std::puts()/std::fputs() (for unformatted strings).
- A wpi/fmt/raw_ostream.h header has been added to enable
fmt::print() with wpi::raw_ostream
2021-06-06 16:13:58 -07:00

93 lines
2.7 KiB
C++

// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "wpi/uv/GetNameInfo.h"
#include "wpi/uv/Loop.h"
#include "wpi/uv/util.h"
namespace wpi::uv {
GetNameInfoReq::GetNameInfoReq() {
error = [this](Error err) { GetLoop().error(err); };
}
void GetNameInfo(Loop& loop, const std::shared_ptr<GetNameInfoReq>& req,
const sockaddr& addr, int flags) {
int err = uv_getnameinfo(
loop.GetRaw(), req->GetRaw(),
[](uv_getnameinfo_t* req, int status, const char* hostname,
const char* service) {
auto& h = *static_cast<GetNameInfoReq*>(req->data);
if (status < 0) {
h.ReportError(status);
} else {
h.resolved(hostname, service);
}
h.Release(); // this is always a one-shot
},
&addr, flags);
if (err < 0) {
loop.ReportError(err);
} else {
req->Keep();
}
}
void GetNameInfo(Loop& loop,
std::function<void(const char*, const char*)> callback,
const sockaddr& addr, int flags) {
auto req = std::make_shared<GetNameInfoReq>();
req->resolved.connect(callback);
GetNameInfo(loop, req, addr, flags);
}
void GetNameInfo4(Loop& loop, const std::shared_ptr<GetNameInfoReq>& req,
std::string_view ip, unsigned int port, int flags) {
sockaddr_in addr;
int err = NameToAddr(ip, port, &addr);
if (err < 0) {
loop.ReportError(err);
} else {
GetNameInfo(loop, req, reinterpret_cast<const sockaddr&>(addr), flags);
}
}
void GetNameInfo4(Loop& loop,
std::function<void(const char*, const char*)> callback,
std::string_view ip, unsigned int port, int flags) {
sockaddr_in addr;
int err = NameToAddr(ip, port, &addr);
if (err < 0) {
loop.ReportError(err);
} else {
GetNameInfo(loop, callback, reinterpret_cast<const sockaddr&>(addr), flags);
}
}
void GetNameInfo6(Loop& loop, const std::shared_ptr<GetNameInfoReq>& req,
std::string_view ip, unsigned int port, int flags) {
sockaddr_in6 addr;
int err = NameToAddr(ip, port, &addr);
if (err < 0) {
loop.ReportError(err);
} else {
GetNameInfo(loop, req, reinterpret_cast<const sockaddr&>(addr), flags);
}
}
void GetNameInfo6(Loop& loop,
std::function<void(const char*, const char*)> callback,
std::string_view ip, unsigned int port, int flags) {
sockaddr_in6 addr;
int err = NameToAddr(ip, port, &addr);
if (err < 0) {
loop.ReportError(err);
} else {
GetNameInfo(loop, callback, reinterpret_cast<const sockaddr&>(addr), flags);
}
}
} // namespace wpi::uv