Skip to content

Commit

Permalink
Simplify DNS resolver when resolving both v4 and v6.
Browse files Browse the repository at this point in the history
  • Loading branch information
Barenboim committed Feb 14, 2025
1 parent 50d7c52 commit 4bf00f8
Showing 1 changed file with 19 additions and 33 deletions.
52 changes: 19 additions & 33 deletions src/nameservice/WFDnsResolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,8 @@ using thread_dns_callback_t = std::function<void (ThreadDnsTask *)>;

struct DnsContext
{
int state;
int error;
int eai_error;
unsigned short port;
int eai_error;
struct addrinfo *ai;
};

Expand Down Expand Up @@ -662,10 +660,9 @@ void WFResolverTask::dns_partial_callback(void *net_dns_task)
WFGlobal::get_dns_respool()->post(NULL);

struct DnsContext *ctx = (struct DnsContext *)dns_task->user_data;

ctx->ai = NULL;
ctx->state = dns_task->get_state();
ctx->error = dns_task->get_error();
if (ctx->state == WFT_STATE_SUCCESS)
if (dns_task->get_state() == WFT_STATE_SUCCESS)
{
protocol::DnsResponse *resp = dns_task->get_resp();
ctx->eai_error = protocol::DnsUtil::getaddrinfo(resp, ctx->port,
Expand All @@ -678,46 +675,35 @@ void WFResolverTask::dns_partial_callback(void *net_dns_task)
void WFResolverTask::dns_parallel_callback(const void *parallel)
{
const ParallelWork *pwork = (const ParallelWork *)parallel;
struct DnsContext *c4 = (struct DnsContext *)(pwork->get_context());
struct DnsContext *c4 = (struct DnsContext *)pwork->get_context();
struct DnsContext *c6 = c4 + 1;
DnsOutput out;

if (c4->state != WFT_STATE_SUCCESS && c6->state != WFT_STATE_SUCCESS)
{
this->state = WFT_STATE_DNS_ERROR;
this->error = EAI_AGAIN;
}
else if (c4->eai_error != 0 && c6->eai_error != 0)
if (c4->eai_error == 0 || c6->eai_error == 0)
{
int eai_error = c4->eai_error;
struct addrinfo *ai = NULL;
struct addrinfo **pai = &ai;
DnsOutput out;

if (c6->eai_error == EAI_AGAIN)
eai_error = EAI_AGAIN;
*pai = c4->ai;
while (*pai)
pai = &(*pai)->ai_next;

DnsRoutine::create(&out, eai_error, NULL);
*pai = c6->ai;
DnsRoutine::create(&out, 0, ai);
dns_callback_internal(&out, dns_ttl_default_, dns_ttl_min_);
}
else
{
struct addrinfo *ai = NULL;
struct addrinfo **pai = &ai;

if (c4->ai != NULL)
{
*pai = c4->ai;
while (*pai)
pai = &(*pai)->ai_next;
}
int eai_error = c4->eai_error;

if (c6->ai != NULL)
*pai = c6->ai;
if (c6->eai_error == EAI_AGAIN)
eai_error = EAI_AGAIN;

DnsRoutine::create(&out, 0, ai);
dns_callback_internal(&out, dns_ttl_default_, dns_ttl_min_);
this->state = WFT_STATE_DNS_ERROR;
this->error = eai_error;
}

delete[] c4;

delete []c4;
task_callback();
}

Expand Down

0 comments on commit 4bf00f8

Please sign in to comment.