backport needed fixes

v1.32
Brad House 3 months ago
parent f154a6cad3
commit 6385409913
  1. 38
      test/ares-test.cc
  2. 47
      test/ares-test.h

38
test/ares-test.cc vendored

@ -1023,6 +1023,44 @@ void HostCallback(void *data, int status, int timeouts,
if (verbose) std::cerr << "HostCallback(" << *result << ")" << std::endl;
}
std::ostream& operator<<(std::ostream& os, const AresDnsRecord& dnsrec) {
os << "{'";
/* XXX: Todo */
os << '}';
return os;
}
std::ostream& operator<<(std::ostream& os, const QueryResult& result) {
os << '{';
if (result.done_) {
os << StatusToString(result.status_);
if (result.dnsrec_.dnsrec_ != nullptr) {
os << " " << result.dnsrec_;
} else {
os << ", (no dnsrec)";
}
} else {
os << "(incomplete)";
}
os << '}';
return os;
}
void QueryCallback(void *data, ares_status_t status, size_t timeouts,
const ares_dns_record_t *dnsrec) {
EXPECT_NE(nullptr, data);
if (data == nullptr)
return;
QueryResult* result = reinterpret_cast<QueryResult*>(data);
result->done_ = true;
result->status_ = status;
result->timeouts_ = timeouts;
if (dnsrec)
result->dnsrec_.SetDnsRecord(dnsrec);
if (verbose) std::cerr << "QueryCallback(" << *result << ")" << std::endl;
}
std::ostream& operator<<(std::ostream& os, const AddrInfoResult& result) {
os << '{';
if (result.done_ && result.ai_) {

47
test/ares-test.h vendored

@ -496,6 +496,51 @@ struct HostResult {
std::ostream &operator<<(std::ostream &os, const HostResult &result);
// C++ wrapper for ares_dns_record_t.
struct AresDnsRecord {
~AresDnsRecord()
{
ares_dns_record_destroy(dnsrec_);
dnsrec_ = NULL;
}
AresDnsRecord() : dnsrec_(NULL)
{
}
void SetDnsRecord(const ares_dns_record_t *dnsrec)
{
if (dnsrec_ != NULL) {
ares_dns_record_destroy(dnsrec_);
}
if (dnsrec == NULL) {
return;
}
dnsrec_ = ares_dns_record_duplicate(dnsrec);
}
ares_dns_record_t *dnsrec_ = NULL;
};
std::ostream &operator<<(std::ostream &os, const AresDnsRecord &result);
// Structure that describes the result of an ares_host_callback invocation.
struct QueryResult {
QueryResult() : done_(false), status_(ARES_SUCCESS), timeouts_(0)
{
}
// Whether the callback has been invoked.
bool done_;
// Explicitly provided result information.
ares_status_t status_;
size_t timeouts_;
// Contents of the ares_dns_record_t structure if provided
AresDnsRecord dnsrec_;
};
std::ostream &operator<<(std::ostream &os, const QueryResult &result);
// Structure that describes the result of an ares_callback invocation.
struct SearchResult {
// Whether the callback has been invoked.
@ -556,6 +601,8 @@ std::ostream &operator<<(std::ostream &os, const AddrInfoResult &result);
// structures.
void HostCallback(void *data, int status, int timeouts,
struct hostent *hostent);
void QueryCallback(void *data, ares_status_t status, size_t timeouts,
const ares_dns_record_t *dnsrec);
void SearchCallback(void *data, int status, int timeouts, unsigned char *abuf,
int alen);
void SearchCallbackDnsRec(void *data, ares_status_t status, size_t timeouts,

Loading…
Cancel
Save