mirror of https://github.com/aria2/aria2
Check the availability of ares_set_servers and ares_addr_node.
parent
8386013296
commit
d3d1293974
|
@ -26,7 +26,10 @@ if test "x$have_libcares" != "xyes"; then
|
|||
fi
|
||||
|
||||
if test "x$have_libcares" = "xyes"; then
|
||||
|
||||
if test "x$need_librt" = "xyes"; then
|
||||
LIBS="-lrt $LIBS"
|
||||
fi
|
||||
LIBS="-lcares $LIBS"
|
||||
AC_MSG_CHECKING([whether ares_host_callback accepts timeouts(c-ares >= 1.5)])
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
|
||||
#include <ares.h>
|
||||
|
@ -43,6 +46,8 @@ if test "x$have_libcares" = "xyes"; then
|
|||
if test "x$have_libcares1_5" = "xyes"; then
|
||||
AC_DEFINE([HAVE_LIBCARES1_5], [1], [Define 1 if ares_host_callback accepts timeouts(c-ares >= 1.5)])
|
||||
fi
|
||||
AC_CHECK_TYPES([ares_addr_node], [], [], [[#include <ares.h>]])
|
||||
AC_CHECK_FUNCS([ares_set_servers])
|
||||
|
||||
AC_DEFINE([HAVE_LIBCARES], [1], [Define to 1 if you have libcares.])
|
||||
LIBCARES_LIBS="-L$libcares_prefix_lib -lcares"
|
||||
|
|
|
@ -651,7 +651,12 @@ void AbstractCommand::initAsyncNameResolver(const std::string& hostname)
|
|||
family = AF_INET;
|
||||
}
|
||||
asyncNameResolver_.reset
|
||||
(new AsyncNameResolver(family, e_->getAsyncDNSServers()));
|
||||
(new AsyncNameResolver(family
|
||||
#ifdef HAVE_ARES_ADDR_NODE
|
||||
,
|
||||
e_->getAsyncDNSServers()
|
||||
#endif // HAVE_ARES_ADDR_NODE
|
||||
));
|
||||
A2_LOG_INFO(fmt(MSG_RESOLVING_HOSTNAME,
|
||||
getCuid(),
|
||||
hostname.c_str()));
|
||||
|
|
|
@ -78,18 +78,25 @@ void callback(void* arg, int status, int timeouts, struct hostent* host)
|
|||
}
|
||||
}
|
||||
|
||||
AsyncNameResolver::AsyncNameResolver(int family, ares_addr_node* servers):
|
||||
status_(STATUS_READY),
|
||||
family_(family)
|
||||
AsyncNameResolver::AsyncNameResolver
|
||||
(int family
|
||||
#ifdef HAVE_ARES_ADDR_NODE
|
||||
, ares_addr_node* servers
|
||||
#endif // HAVE_ARES_ADDR_NODE
|
||||
)
|
||||
: status_(STATUS_READY),
|
||||
family_(family)
|
||||
{
|
||||
// TODO evaluate return value
|
||||
ares_init(&channel_);
|
||||
#if defined HAVE_ARES_SET_SERVERS && HAVE_ARES_ADDR_NODE
|
||||
if(servers) {
|
||||
// ares_set_servers has been added since c-ares 1.7.1
|
||||
if(ares_set_servers(channel_, servers) != ARES_SUCCESS) {
|
||||
A2_LOG_DEBUG("ares_set_servers failed");
|
||||
}
|
||||
}
|
||||
#endif // HAVE_ARES_SET_SERVERS && HAVE_ARES_ADDR_NODE
|
||||
}
|
||||
|
||||
AsyncNameResolver::~AsyncNameResolver()
|
||||
|
|
|
@ -70,7 +70,12 @@ private:
|
|||
std::string error_;
|
||||
std::string hostname_;
|
||||
public:
|
||||
AsyncNameResolver(int family, ares_addr_node* servers);
|
||||
AsyncNameResolver
|
||||
(int family
|
||||
#ifdef HAVE_ARES_ADDR_NODE
|
||||
, ares_addr_node* servers
|
||||
#endif // HAVE_ARES_ADDR_NODE
|
||||
);
|
||||
|
||||
~AsyncNameResolver();
|
||||
|
||||
|
|
|
@ -84,7 +84,11 @@ bool DHTEntryPointNameResolveCommand::execute()
|
|||
} else {
|
||||
family = AF_INET;
|
||||
}
|
||||
resolver_.reset(new AsyncNameResolver(family, e_->getAsyncDNSServers()));
|
||||
resolver_.reset(new AsyncNameResolver(family
|
||||
#ifdef HAVE_ARES_ADDR_NODE
|
||||
, e_->getAsyncDNSServers()
|
||||
#endif // HAVE_ARES_ADDR_NODE
|
||||
));
|
||||
}
|
||||
#endif // ENABLE_ASYNC_DNS
|
||||
try {
|
||||
|
|
|
@ -95,9 +95,9 @@ DownloadEngine::DownloadEngine(const SharedHandle<EventPoll>& eventPoll)
|
|||
#ifdef ENABLE_BITTORRENT
|
||||
btRegistry_(new BtRegistry()),
|
||||
#endif // ENABLE_BITTORRENT
|
||||
#ifdef ENABLE_ASYNC_DNS
|
||||
#ifdef HAVE_ARES_ADDR_NODE
|
||||
asyncDNSServers_(0),
|
||||
#endif // ENABLE_ASYNC_DNS
|
||||
#endif // HAVE_ARES_ADDR_NODE
|
||||
dnsCache_(new DNSCache())
|
||||
{
|
||||
unsigned char sessionId[20];
|
||||
|
@ -107,7 +107,9 @@ DownloadEngine::DownloadEngine(const SharedHandle<EventPoll>& eventPoll)
|
|||
|
||||
DownloadEngine::~DownloadEngine() {
|
||||
cleanQueue();
|
||||
#ifdef HAVE_ARES_ADDR_NODE
|
||||
setAsyncDNSServers(0);
|
||||
#endif // HAVE_ARES_ADDR_NODE
|
||||
}
|
||||
|
||||
void DownloadEngine::cleanQueue() {
|
||||
|
@ -564,6 +566,7 @@ void DownloadEngine::setCheckIntegrityMan
|
|||
checkIntegrityMan_ = ciman;
|
||||
}
|
||||
|
||||
#ifdef HAVE_ARES_ADDR_NODE
|
||||
void DownloadEngine::setAsyncDNSServers(ares_addr_node* asyncDNSServers)
|
||||
{
|
||||
ares_addr_node* node = asyncDNSServers_;
|
||||
|
@ -574,5 +577,6 @@ void DownloadEngine::setAsyncDNSServers(ares_addr_node* asyncDNSServers)
|
|||
}
|
||||
asyncDNSServers_ = asyncDNSServers;
|
||||
}
|
||||
#endif // HAVE_ARES_ADDR_NODE
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -135,9 +135,9 @@ private:
|
|||
|
||||
CUIDCounter cuidCounter_;
|
||||
|
||||
#ifdef ENABLE_ASYNC_DNS
|
||||
#ifdef HAVE_ARES_ADDR_NODE
|
||||
ares_addr_node* asyncDNSServers_;
|
||||
#endif // ENABLE_ASYNC_DNS
|
||||
#endif // HAVE_ARES_ADDR_NODE
|
||||
|
||||
SharedHandle<DNSCache> dnsCache_;
|
||||
|
||||
|
@ -331,12 +331,14 @@ public:
|
|||
return sessionId_;
|
||||
}
|
||||
|
||||
#ifdef HAVE_ARES_ADDR_NODE
|
||||
void setAsyncDNSServers(ares_addr_node* asyncDNSServers);
|
||||
|
||||
ares_addr_node* getAsyncDNSServers() const
|
||||
{
|
||||
return asyncDNSServers_;
|
||||
}
|
||||
#endif // HAVE_ARES_ADDR_NODE
|
||||
};
|
||||
|
||||
typedef SharedHandle<DownloadEngine> DownloadEngineHandle;
|
||||
|
|
|
@ -215,10 +215,11 @@ error_code::Value MultiUrlRequestInfo::execute()
|
|||
}
|
||||
SocketCore::setTLSContext(tlsContext);
|
||||
#endif
|
||||
#ifdef HAVE_ARES_ADDR_NODE
|
||||
ares_addr_node* asyncDNSServers =
|
||||
parseAsyncDNSServers(option_->get(PREF_ASYNC_DNS_SERVER));
|
||||
e->setAsyncDNSServers(asyncDNSServers);
|
||||
|
||||
#endif // HAVE_ARES_ADDR_NODE
|
||||
if(!Timer::monotonicClock()) {
|
||||
A2_LOG_WARN("Don't change system time while aria2c is running."
|
||||
" Doing this may make aria2c hang for long time.");
|
||||
|
|
|
@ -89,6 +89,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
|
|||
op->addTag(TAG_ADVANCED);
|
||||
handlers.push_back(op);
|
||||
}
|
||||
#if defined HAVE_ARES_SET_SERVERS && HAVE_ARES_ADDR_NODE
|
||||
{
|
||||
SharedHandle<OptionHandler> op(new DefaultOptionHandler
|
||||
(PREF_ASYNC_DNS_SERVER,
|
||||
|
@ -97,6 +98,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
|
|||
op->addTag(TAG_ADVANCED);
|
||||
handlers.push_back(op);
|
||||
}
|
||||
#endif // HAVE_ARES_SET_SERVERS && HAVE_ARES_ADDR_NODE
|
||||
#endif // ENABLE_ASYNC_DNS
|
||||
{
|
||||
SharedHandle<OptionHandler> op(new BooleanOptionHandler
|
||||
|
|
Loading…
Reference in New Issue