/* */ #include "CreateRequestCommand.h" #include "InitiateConnectionCommandFactory.h" #include "RequestGroup.h" #include "Segment.h" #include "DownloadContext.h" #include "DlAbortEx.h" #include "DownloadEngine.h" #include "SocketCore.h" #include "SegmentMan.h" #include "prefs.h" #include "Option.h" namespace aria2 { CreateRequestCommand::CreateRequestCommand(int32_t cuid, RequestGroup* requestGroup, DownloadEngine* e): AbstractCommand (cuid, SharedHandle(), SharedHandle(), requestGroup, e) { setStatus(Command::STATUS_ONESHOT_REALTIME); disableReadCheckSocket(); disableWriteCheckSocket(); } bool CreateRequestCommand::executeInternal() { if(_segments.empty()) { _fileEntry = _requestGroup->getDownloadContext()->findFileEntryByOffset(0); } else { // We assume all segments belongs to same file. _fileEntry = _requestGroup->getDownloadContext()->findFileEntryByOffset (_segments.front()->getPositionToWrite()); } if(_fileEntry->getRemainingUris().empty() && getOption()->getAsBool(PREF_REUSE_URI)) { _fileEntry->reuseUri(_requestGroup->getNumConcurrentCommand()); } req = _fileEntry->getRequest(_requestGroup->getURISelector(), getOption()->get(PREF_REFERER), // Don't use HEAD request when file // size is known. _fileEntry->getLength() == 0 && getOption()->getAsBool(PREF_USE_HEAD)? Request::METHOD_HEAD:Request::METHOD_GET); if(req.isNull()) { if(!_requestGroup->getSegmentMan().isNull()) { _requestGroup->getSegmentMan()->ignoreSegmentFor(_fileEntry); } throw DL_ABORT_EX("No URI available."); } Command* command = InitiateConnectionCommandFactory::createInitiateConnectionCommand (cuid, req, _fileEntry, _requestGroup, e); e->setNoWait(true); e->commands.push_back(command); return true; } } // namespace aria2