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
pull/1/head
Tatsuhiro Tsujikawa 2010-10-02 10:12:10 +00:00
parent 86d4d1963a
commit 7375a778c4
3 changed files with 47 additions and 13 deletions

View File

@ -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()

View File

@ -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,

View File

@ -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;