summaryrefslogtreecommitdiff
path: root/src/DownloadEngine.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2006-08-11 12:29:55 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2006-08-11 12:29:55 +0000
commitf2d4faad083ffb1bdf622090f63283150bd95aeb (patch)
treedbcff240417b7879e93958a2fbbf493b83a943bc /src/DownloadEngine.cc
parent7ca1b43eddd1aba1c71a38dfb46b5ac5685b43d0 (diff)
2006-08-11 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To add asynchronous DNS support(libares): * src/AbstractCommand.h (setNameResolverCheck): New function. (disableNameResolverCheck): New function (resolveHostname): New function. * src/AbstractCommand.cc (setNameResolverCheck): New function. (disableNameResolverCheck): New function (resolveHostname): New function. * src/FtpInitiateConnectionCommand.h (nameResolver): New function. * src/FtpInitiateConnectionCommand.cc (Util.h): Included. (FtpInitiateConnectionCommand): Call disableReadCheckSocket, disableWriteCheckSocket. (~FtpInitiateConnectionCommand): Call disableNameResolverCheck. (executeInternal): Added async DNS support. * src/HttpInitiateConnectionCommand.h (nameResolver): New function. * src/HttpInitiateConnectionCommand.cc (DlRetryEx.h): Included. (HttpInitiateConnectionCommand): Call disableReadCheckSocket, disableWriteCheckSocket. (~HttpInitiateConnectionCommand): Call disableNameResolverCheck. (executeInternal): Added async DNS support. * src/NameResolver.h: New class. Note: #include <ares.h> is surrounded by extern "C" declaration. * src/NameResolver.cc: New class. * src/Util.h: (isNumberAndDotsNotation): New function * src/Util.cc (isNumberAndDotsNotation): New function. * src/DownloadEngine.h (NameResolver.h): Included. (NameResolverEntry): New class. (NameResolverEntries): New type definition. (addNameResolverCheck): New function. (deleteNameResolverCheck): New function. * src/DownloadEngine.cc (run): Initialize cp with 0. (SetDescriptor::operator()): Added for NameResolverEntry. (AccumulateActiveUuid::operator()): Added for NameResolverEntry. (waitData): Check nameResolver entries. (updateFdSet): Update fds in nameResolver entries. (addNameResolverCheck): New function. (deleteNameResolverCheck): new function. * src/PeerInteractionCommand.cc (executeInternal): Fixed wrong socket handling. * src/main.cc (main): Fixed the initial value of PREF_LOWEST_SPEED_LIMIT option to 0. * src/Util.cc (fileChecksum): Removed the call to ctx.digestReset().
Diffstat (limited to 'src/DownloadEngine.cc')
-rw-r--r--src/DownloadEngine.cc63
1 files changed, 62 insertions, 1 deletions
diff --git a/src/DownloadEngine.cc b/src/DownloadEngine.cc
index 912381da..9229acd2 100644
--- a/src/DownloadEngine.cc
+++ b/src/DownloadEngine.cc
@@ -65,6 +65,7 @@ public:
void DownloadEngine::run() {
initStatistics();
Time cp;
+ cp.setTimeInSec(0);
CommandUuids activeUuids;
while(!commands.empty()) {
if(cp.elapsed(1)) {
@@ -135,6 +136,14 @@ public:
*max_ptr = fd;
}
}
+#ifdef HAVE_LIBARES
+ void operator()(const NameResolverEntry& entry) {
+ int tempFd = entry.nameResolver->getFds(rfds_ptr, wfds_ptr);
+ if(*max_ptr < tempFd) {
+ *max_ptr = tempFd;
+ }
+ }
+#endif // HAVE_LIBARES
};
class AccumulateActiveUuid {
@@ -170,6 +179,19 @@ public:
}
*/
}
+#ifdef HAVE_LIBARES
+ void operator()(const NameResolverEntry& entry) {
+ entry.nameResolver->process(rfds_ptr, wfds_ptr);
+ switch(entry.nameResolver->getStatus()) {
+ case NameResolver::STATUS_SUCCESS:
+ case NameResolver::STATUS_ERROR:
+ activeUuids_ptr->push_back(entry.commandUuid);
+ break;
+ default:
+ break;
+ }
+ }
+#endif // HAVE_LIBARES
};
void DownloadEngine::waitData(CommandUuids& activeUuids) {
@@ -187,7 +209,10 @@ void DownloadEngine::waitData(CommandUuids& activeUuids) {
if(retval > 0) {
for_each(socketEntries.begin(), socketEntries.end(),
AccumulateActiveUuid(&activeUuids, &rfds, &wfds));
-
+#ifdef HAVE_LIBARES
+ for_each(nameResolverEntries.begin(), nameResolverEntries.end(),
+ AccumulateActiveUuid(&activeUuids, &rfds, &wfds));
+#endif // HAVE_LIBARES
sort(activeUuids.begin(), activeUuids.end());
activeUuids.erase(unique(activeUuids.begin(),
activeUuids.end()),
@@ -199,6 +224,10 @@ void DownloadEngine::updateFdSet() {
fdmax = 0;
FD_ZERO(&rfdset);
FD_ZERO(&wfdset);
+#ifdef HAVE_LIBARES
+ for_each(nameResolverEntries.begin(), nameResolverEntries.end(),
+ SetDescriptor(&fdmax, &rfdset, &wfdset));
+#endif // HAVE_LIBARES
for_each(socketEntries.begin(), socketEntries.end(),
SetDescriptor(&fdmax, &rfdset, &wfdset));
}
@@ -250,3 +279,35 @@ bool DownloadEngine::deleteSocketForWriteCheck(const SocketHandle& socket,
SocketEntry entry(socket, commandUuid, SocketEntry::TYPE_WR);
return deleteSocket(entry);
}
+
+#ifdef HAVE_LIBARES
+bool DownloadEngine::addNameResolverCheck(const NameResolverHandle& resolver,
+ const CommandUuid& uuid) {
+ NameResolverEntry entry(resolver, uuid);
+ NameResolverEntries::iterator itr = find(nameResolverEntries.begin(),
+ nameResolverEntries.end(),
+ entry);
+ if(itr == nameResolverEntries.end()) {
+ nameResolverEntries.push_back(entry);
+ updateFdSet();
+ return true;
+ } else {
+ return false;
+ }
+}
+
+bool DownloadEngine::deleteNameResolverCheck(const NameResolverHandle& resolver,
+ const CommandUuid& uuid) {
+ NameResolverEntry entry(resolver, uuid);
+ NameResolverEntries::iterator itr = find(nameResolverEntries.begin(),
+ nameResolverEntries.end(),
+ entry);
+ if(itr == nameResolverEntries.end()) {
+ return false;
+ } else {
+ nameResolverEntries.erase(itr);
+ updateFdSet();
+ return true;
+ }
+}
+#endif // HAVE_LIBARES