/* */ #include "SftpDownloadCommand.h" #include "Request.h" #include "SocketCore.h" #include "Segment.h" #include "DownloadEngine.h" #include "RequestGroup.h" #include "Option.h" #include "FileEntry.h" #include "SocketRecvBuffer.h" #include "AuthConfig.h" #include "SftpFinishDownloadCommand.h" namespace aria2 { SftpDownloadCommand::SftpDownloadCommand (cuid_t cuid, const std::shared_ptr& req, const std::shared_ptr& fileEntry, RequestGroup* requestGroup, DownloadEngine* e, const std::shared_ptr& socket, std::unique_ptr authConfig) : DownloadCommand(cuid, req, fileEntry, requestGroup, e, socket, std::make_shared(socket)), authConfig_(std::move(authConfig)) { setWriteCheckSocket(getSocket()); } SftpDownloadCommand::~SftpDownloadCommand() {} bool SftpDownloadCommand::prepareForNextSegment() { if(getOption()->getAsBool(PREF_FTP_REUSE_CONNECTION) && getFileEntry()->gtoloff(getSegments().front()->getPositionToWrite()) == getFileEntry()->getLength()) { auto c = make_unique (getCuid(), getRequest(), getFileEntry(), getRequestGroup(), getDownloadEngine(), getSocket()); c->setStatus(Command::STATUS_ONESHOT_REALTIME); getDownloadEngine()->setNoWait(true); getDownloadEngine()->addCommand(std::move(c)); if(getRequestGroup()->downloadFinished()) { // To run checksum checking, we had to call following function here. DownloadCommand::prepareForNextSegment(); } return true; } auto rv = DownloadCommand::prepareForNextSegment(); if (rv) { return true; } // sftp may not get incoming data. Enable write check to make this // command invoke. setWriteCheckSocket(getSocket()); return false; } int64_t SftpDownloadCommand::getRequestEndOffset() const { return getFileEntry()->getLength(); } bool SftpDownloadCommand::shouldEnableWriteCheck() { return getSocket()->wantWrite() || !getSocket()->wantRead(); } } // namespace aria2