Fix mysterious 1 second delay with async DNS

pull/538/head
Tatsuhiro Tsujikawa 2016-01-19 10:42:25 +09:00
parent e6b6aa324b
commit ffec92ec57
2 changed files with 36 additions and 38 deletions

View File

@ -170,30 +170,29 @@ int DHTEntryPointNameResolveCommand::resolveHostname(
{
if (!asyncNameResolverMan_->started()) {
asyncNameResolverMan_->startAsync(hostname, e_, this);
return 0;
}
else {
switch (asyncNameResolverMan_->getStatus()) {
case -1:
switch (asyncNameResolverMan_->getStatus()) {
case -1:
A2_LOG_INFO(fmt(MSG_NAME_RESOLUTION_FAILED, getCuid(), hostname.c_str(),
asyncNameResolverMan_->getLastError().c_str()));
return -1;
case 0:
return 0;
case 1:
asyncNameResolverMan_->getResolvedAddress(res);
if (res.empty()) {
A2_LOG_INFO(fmt(MSG_NAME_RESOLUTION_FAILED, getCuid(), hostname.c_str(),
asyncNameResolverMan_->getLastError().c_str()));
"No address returned"));
return -1;
case 0:
return 0;
case 1:
asyncNameResolverMan_->getResolvedAddress(res);
if (res.empty()) {
A2_LOG_INFO(fmt(MSG_NAME_RESOLUTION_FAILED, getCuid(), hostname.c_str(),
"No address returned"));
return -1;
}
else {
A2_LOG_INFO(fmt(MSG_NAME_RESOLUTION_COMPLETE, getCuid(),
hostname.c_str(), res.front().c_str()));
return 1;
}
}
else {
A2_LOG_INFO(fmt(MSG_NAME_RESOLUTION_COMPLETE, getCuid(), hostname.c_str(),
res.front().c_str()));
return 1;
}
}
// Unreachable
return 0;
}

View File

@ -148,30 +148,29 @@ int NameResolveCommand::resolveHostname(std::vector<std::string>& res,
{
if (!asyncNameResolverMan_->started()) {
asyncNameResolverMan_->startAsync(hostname, e_, this);
return 0;
}
else {
switch (asyncNameResolverMan_->getStatus()) {
case -1:
switch (asyncNameResolverMan_->getStatus()) {
case -1:
A2_LOG_INFO(fmt(MSG_NAME_RESOLUTION_FAILED, getCuid(), hostname.c_str(),
asyncNameResolverMan_->getLastError().c_str()));
return -1;
case 0:
return 0;
case 1:
asyncNameResolverMan_->getResolvedAddress(res);
if (res.empty()) {
A2_LOG_INFO(fmt(MSG_NAME_RESOLUTION_FAILED, getCuid(), hostname.c_str(),
asyncNameResolverMan_->getLastError().c_str()));
"No address returned"));
return -1;
case 0:
return 0;
case 1:
asyncNameResolverMan_->getResolvedAddress(res);
if (res.empty()) {
A2_LOG_INFO(fmt(MSG_NAME_RESOLUTION_FAILED, getCuid(), hostname.c_str(),
"No address returned"));
return -1;
}
else {
A2_LOG_INFO(fmt(MSG_NAME_RESOLUTION_COMPLETE, getCuid(),
hostname.c_str(), res.front().c_str()));
return 1;
}
}
else {
A2_LOG_INFO(fmt(MSG_NAME_RESOLUTION_COMPLETE, getCuid(), hostname.c_str(),
res.front().c_str()));
return 1;
}
}
// Unreachable
return 0;
}