mirror of https://github.com/aria2/aria2
Rewrite async DNS portion without exception
parent
497c1dd8c9
commit
d575e3cc77
|
@ -94,31 +94,21 @@ bool DHTEntryPointNameResolveCommand::execute()
|
||||||
entryPoints_.front().second);
|
entryPoints_.front().second);
|
||||||
addPingTask(p);
|
addPingTask(p);
|
||||||
} else {
|
} else {
|
||||||
try {
|
std::vector<std::string> res;
|
||||||
if(resolveHostname(hostname)) {
|
int rv = resolveHostname(res, hostname);
|
||||||
std::vector<std::string> addrs;
|
if(rv == 0) {
|
||||||
asyncNameResolverMan_->getResolvedAddress(addrs);
|
|
||||||
if(addrs.empty()) {
|
|
||||||
A2_LOG_ERROR(fmt("No address returned for %s",
|
|
||||||
hostname.c_str()));
|
|
||||||
} else {
|
|
||||||
A2_LOG_INFO(fmt(MSG_NAME_RESOLUTION_COMPLETE,
|
|
||||||
getCuid(), hostname.c_str(),
|
|
||||||
addrs.front().c_str()));
|
|
||||||
++numSuccess_;
|
|
||||||
std::pair<std::string, uint16_t> p
|
|
||||||
(addrs.front(), entryPoints_.front().second);
|
|
||||||
addPingTask(p);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
e_->addCommand(this);
|
e_->addCommand(this);
|
||||||
return false;
|
return false;
|
||||||
}
|
} else {
|
||||||
} catch(RecoverableException& e) {
|
if(rv == 1) {
|
||||||
A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
|
++numSuccess_;
|
||||||
|
std::pair<std::string, uint16_t> p
|
||||||
|
(res.front(), entryPoints_.front().second);
|
||||||
|
addPingTask(p);
|
||||||
}
|
}
|
||||||
asyncNameResolverMan_->reset(e_, this);
|
asyncNameResolverMan_->reset(e_, this);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
entryPoints_.pop_front();
|
entryPoints_.pop_front();
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
|
@ -165,25 +155,37 @@ void DHTEntryPointNameResolveCommand::addPingTask
|
||||||
|
|
||||||
#ifdef ENABLE_ASYNC_DNS
|
#ifdef ENABLE_ASYNC_DNS
|
||||||
|
|
||||||
bool DHTEntryPointNameResolveCommand::resolveHostname
|
int DHTEntryPointNameResolveCommand::resolveHostname
|
||||||
(const std::string& hostname)
|
(std::vector<std::string>& res, const std::string& hostname)
|
||||||
{
|
{
|
||||||
if(!asyncNameResolverMan_->started()) {
|
if(!asyncNameResolverMan_->started()) {
|
||||||
asyncNameResolverMan_->startAsync(hostname, e_, this);
|
asyncNameResolverMan_->startAsync(hostname, e_, this);
|
||||||
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
switch(asyncNameResolverMan_->getStatus()) {
|
switch(asyncNameResolverMan_->getStatus()) {
|
||||||
case -1:
|
case -1:
|
||||||
throw DL_ABORT_EX2
|
A2_LOG_INFO
|
||||||
(fmt(MSG_NAME_RESOLUTION_FAILED, getCuid(), hostname.c_str(),
|
(fmt(MSG_NAME_RESOLUTION_FAILED, getCuid(), hostname.c_str(),
|
||||||
asyncNameResolverMan_->getLastError().c_str()),
|
asyncNameResolverMan_->getLastError().c_str()));
|
||||||
error_code::NAME_RESOLVE_ERROR);
|
return -1;
|
||||||
case 0:
|
case 0:
|
||||||
return false;
|
return 0;
|
||||||
case 1:
|
case 1:
|
||||||
return true;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
}
|
||||||
|
// Unreachable
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // ENABLE_ASYNC_DNS
|
#endif // ENABLE_ASYNC_DNS
|
||||||
|
|
|
@ -80,7 +80,8 @@ private:
|
||||||
void addPingTask(const std::pair<std::string, uint16_t>& addr);
|
void addPingTask(const std::pair<std::string, uint16_t>& addr);
|
||||||
|
|
||||||
#ifdef ENABLE_ASYNC_DNS
|
#ifdef ENABLE_ASYNC_DNS
|
||||||
bool resolveHostname(const std::string& hostname);
|
int resolveHostname(std::vector<std::string>& res,
|
||||||
|
const std::string& hostname);
|
||||||
#endif // ENABLE_ASYNC_DNS
|
#endif // ENABLE_ASYNC_DNS
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in New Issue