mirror of
https://github.com/sogou/workflow.git
synced 2026-02-08 01:33:17 +08:00
Simplify DNS resolver when resolving both v4 and v6.
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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,
|
||||
@@ -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)
|
||||
if (c4->eai_error == 0 || c6->eai_error == 0)
|
||||
{
|
||||
this->state = WFT_STATE_DNS_ERROR;
|
||||
this->error = EAI_AGAIN;
|
||||
struct addrinfo *ai = NULL;
|
||||
struct addrinfo **pai = &ai;
|
||||
DnsOutput out;
|
||||
|
||||
*pai = c4->ai;
|
||||
while (*pai)
|
||||
pai = &(*pai)->ai_next;
|
||||
|
||||
*pai = c6->ai;
|
||||
DnsRoutine::create(&out, 0, ai);
|
||||
dns_callback_internal(&out, dns_ttl_default_, dns_ttl_min_);
|
||||
}
|
||||
else if (c4->eai_error != 0 && c6->eai_error != 0)
|
||||
else
|
||||
{
|
||||
int eai_error = c4->eai_error;
|
||||
|
||||
if (c6->eai_error == EAI_AGAIN)
|
||||
eai_error = EAI_AGAIN;
|
||||
|
||||
DnsRoutine::create(&out, eai_error, NULL);
|
||||
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;
|
||||
}
|
||||
|
||||
if (c6->ai != NULL)
|
||||
*pai = c6->ai;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user