summaryrefslogtreecommitdiff
path: root/src/FtpInitiateConnectionCommand.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/FtpInitiateConnectionCommand.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/FtpInitiateConnectionCommand.cc')
-rw-r--r--src/FtpInitiateConnectionCommand.cc37
1 files changed, 32 insertions, 5 deletions
diff --git a/src/FtpInitiateConnectionCommand.cc b/src/FtpInitiateConnectionCommand.cc
index 2a67222e..2a6ce116 100644
--- a/src/FtpInitiateConnectionCommand.cc
+++ b/src/FtpInitiateConnectionCommand.cc
@@ -26,10 +26,22 @@
#include "DlAbortEx.h"
#include "message.h"
#include "prefs.h"
+#include "Util.h"
-FtpInitiateConnectionCommand::FtpInitiateConnectionCommand(int cuid, Request* req, DownloadEngine* e):AbstractCommand(cuid, req, e) {}
+FtpInitiateConnectionCommand::FtpInitiateConnectionCommand(int cuid,
+ Request* req,
+ DownloadEngine* e)
+ :AbstractCommand(cuid, req, e)
+{
+ disableReadCheckSocket();
+ disableWriteCheckSocket();
+}
-FtpInitiateConnectionCommand::~FtpInitiateConnectionCommand() {}
+FtpInitiateConnectionCommand::~FtpInitiateConnectionCommand() {
+#ifdef HAVE_LIBARES
+ disableNameResolverCheck(nameResolver);
+#endif // HAVE_LIBARES
+}
bool FtpInitiateConnectionCommand::executeInternal(Segment segment) {
if(!e->segmentMan->downloadStarted) {
@@ -43,13 +55,28 @@ bool FtpInitiateConnectionCommand::executeInternal(Segment segment) {
e->segmentMan->diskWriter->initAndOpenFile(e->segmentMan->getFilePath());
}
}
-
+ string hostname;
+ if(useHttpProxy()) {
+ hostname = e->option->get(PREF_HTTP_PROXY_HOST);
+ } else {
+ hostname = req->getHost();
+ }
+#ifdef HAVE_LIBARES
+ if(!Util::isNumbersAndDotsNotation(hostname)) {
+ if(resolveHostname(hostname, nameResolver)) {
+ hostname = nameResolver->getAddrString();
+ } else {
+ e->commands.push_back(this);
+ return false;
+ }
+ }
+#endif // HAVE_LIBARES
Command* command;
if(useHttpProxy()) {
logger->info(MSG_CONNECTING_TO_SERVER, cuid,
e->option->get(PREF_HTTP_PROXY_HOST).c_str(),
e->option->getAsInt(PREF_HTTP_PROXY_PORT));
- socket->establishConnection(e->option->get(PREF_HTTP_PROXY_HOST),
+ socket->establishConnection(hostname,
e->option->getAsInt(PREF_HTTP_PROXY_PORT));
if(useHttpProxyGet()) {
@@ -63,7 +90,7 @@ bool FtpInitiateConnectionCommand::executeInternal(Segment segment) {
} else {
logger->info(MSG_CONNECTING_TO_SERVER, cuid, req->getHost().c_str(),
req->getPort());
- socket->establishConnection(req->getHost(), req->getPort());
+ socket->establishConnection(hostname, req->getPort());
command = new FtpNegotiationCommand(cuid, req, e, socket);
}
e->commands.push_back(command);