소스 검색

2010-10-02 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Fixed the bug that FtpFinishDownloadCommand does not handle
	timeout. This means it waits for the remote server to send "226
	Transfer Complete" message *without* its own timeout until the
	remote server shutdowns connection(we can detect EOF in this
	case).
	* src/AbstractCommand.h
	* src/FtpFinishDownloadCommand.cc
Tatsuhiro Tsujikawa 15 년 전
부모
커밋
7375a778c4
3개의 변경된 파일47개의 추가작업 그리고 13개의 파일을 삭제
  1. 10 0
      ChangeLog
  2. 10 0
      src/AbstractCommand.h
  3. 27 13
      src/FtpFinishDownloadCommand.cc

+ 10 - 0
ChangeLog

@@ -1,3 +1,13 @@
+2010-10-02  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Fixed the bug that FtpFinishDownloadCommand does not handle
+	timeout. This means it waits for the remote server to send "226
+	Transfer Complete" message *without* its own timeout until the
+	remote server shutdowns connection(we can detect EOF in this
+	case).
+	* src/AbstractCommand.h
+	* src/FtpFinishDownloadCommand.cc
+
 2010-10-02  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Code cleanup util::percentEncode()

+ 10 - 0
src/AbstractCommand.h

@@ -174,6 +174,11 @@ protected:
    */
   void setWriteCheckSocketIf(const SharedHandle<SocketCore>& socket, bool pred);
 
+  time_t getTimeout() const
+  {
+    return timeout_;
+  }
+
   void setTimeout(time_t timeout) { timeout_ = timeout; }
 
   void prepareForNextAction
@@ -222,6 +227,11 @@ protected:
   {
     return requestGroup_->getPieceStorage();
   }
+
+  Timer& getCheckPoint()
+  {
+    return checkPoint_;
+  }
 public:
   AbstractCommand
   (cuid_t cuid, const SharedHandle<Request>& req,

+ 27 - 13
src/FtpFinishDownloadCommand.cc

@@ -52,6 +52,7 @@
 #include "FileAllocationEntry.h"
 #include "CheckIntegrityEntry.h"
 #include "ServerStatMan.h"
+#include "util.h"
 
 namespace aria2 {
 
@@ -75,23 +76,36 @@ bool FtpFinishDownloadCommand::execute()
     return true;
   }
   try {
-    unsigned int status = ftpConnection_->receiveResponse();
-    if(status == 0) {
+    if(readEventEnabled() || hupEventEnabled()) {
+      getCheckPoint().reset();
+      unsigned int status = ftpConnection_->receiveResponse();
+      if(status == 0) {
+        getDownloadEngine()->addCommand(this);
+        return false;
+      }
+      if(status == 226) {
+        if(getOption()->getAsBool(PREF_FTP_REUSE_CONNECTION)) {
+          std::map<std::string, std::string> options;
+          options["baseWorkingDir"] = ftpConnection_->getBaseWorkingDir();
+          getDownloadEngine()->poolSocket
+            (getRequest(), ftpConnection_->getUser(), createProxyRequest(),
+             getSocket(), options);
+        }
+      } else {
+        getLogger()->info("CUID#%s - Bad status for transfer complete.",
+                          util::itos(getCuid()).c_str());
+      }
+    } else if(getCheckPoint().difference(global::wallclock) >= getTimeout()) {
+      getLogger()->info("CUID#%s - Timeout before receiving transfer complete.",
+                        util::itos(getCuid()).c_str());
+    } else {
       getDownloadEngine()->addCommand(this);
       return false;
     }
-    if(status != 226) {
-      throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
-    }
-    if(getOption()->getAsBool(PREF_FTP_REUSE_CONNECTION)) {
-      std::map<std::string, std::string> options;
-      options["baseWorkingDir"] = ftpConnection_->getBaseWorkingDir();
-      getDownloadEngine()->poolSocket
-        (getRequest(), ftpConnection_->getUser(), createProxyRequest(),
-         getSocket(), options);
-    }
   } catch(RecoverableException& e) {
-    getLogger()->info(EX_EXCEPTION_CAUGHT, e);
+    getLogger()->info("CUID#%s - Exception was thrown, but download was"
+                      " finished, so we can ignore the exception.",
+                      e, util::itos(getCuid()).c_str());
   }
   if(getRequestGroup()->downloadFinished()) {
     return true;