From a7952cce05a41c6e20d6eddc569a8bffe974aade Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 26 Apr 2008 08:12:46 +0000 Subject: [PATCH] 2008-04-26 Tatsuhiro Tsujikawa Now auto protocol detection is enabled without -Z option. But there is a important difference between with/without -Z optoin. For example, if you type: aria2c http://host/file file1.torrent file2.metalink http://mirror/file then, aria2 interprets there are 3 request groups: (1) http://host/file, http://mirror/file <-- multi-source download (2) file1.torrent (3) file2.metalink On the other hand, if you invoke above command with -Z option, it is interpreted as 4 request groups: (1) http://host/file (2) file1.torrent (3) file2.metalink (4) http://mirror/file I think usually user don't mix multi-source URLs and torrent files, so there is no big problem here. * src/main.cc --- ChangeLog | 23 +++++++++++++++++++++++ src/main.cc | 26 +++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 38b5aa95..d19495ca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2008-04-26 Tatsuhiro Tsujikawa + + Now auto protocol detection is enabled without -Z option. + But there is a important difference between with/without -Z optoin. + + For example, if you type: + aria2c http://host/file file1.torrent file2.metalink http://mirror/file + then, aria2 interprets there are 3 request groups: + (1) http://host/file, http://mirror/file <-- multi-source download + (2) file1.torrent + (3) file2.metalink + + On the other hand, if you invoke above command with -Z option, it is + interpreted as 4 request groups: + (1) http://host/file + (2) file1.torrent + (3) file2.metalink + (4) http://mirror/file + + I think usually user don't mix multi-source URLs and torrent files, so + there is no big problem here. + * src/main.cc + 2008-04-26 Tatsuhiro Tsujikawa Fixed the bug that causes segmentaion fault when reading XML containing diff --git a/src/main.cc b/src/main.cc index 7a8801f3..4db1226e 100644 --- a/src/main.cc +++ b/src/main.cc @@ -293,6 +293,15 @@ int32_t downloadUriList(Option* op) } } +class StreamProtocolFilter { +private: + ProtocolDetector _detector; +public: + bool operator()(const std::string& uri) { + return _detector.isStreamProtocol(uri); + } +}; + int32_t downloadUri(Option* op, const std::deque& uris) { std::deque nargs; @@ -307,11 +316,22 @@ int32_t downloadUri(Option* op, const std::deque& uris) std::deque >(), AccRequestGroup(op)); } else { + std::deque::iterator strmProtoEnd = + std::stable_partition(nargs.begin(), nargs.end(), StreamProtocolFilter()); + // let's process http/ftp protocols first. std::deque xargs; - ncopy(nargs.begin(), nargs.end(), op->getAsInt(PREF_SPLIT), + ncopy(nargs.begin(), strmProtoEnd, op->getAsInt(PREF_SPLIT), std::back_inserter(xargs)); - RequestGroupHandle rg = createRequestGroup(op, xargs, op->get(PREF_OUT)); - groups.push_back(rg); + if(xargs.size()) { + RequestGroupHandle rg = createRequestGroup(op, xargs, op->get(PREF_OUT)); + groups.push_back(rg); + } + // process remaining URIs(local metalink, BitTorrent files) + std::deque > remGroups = + std::accumulate(strmProtoEnd, nargs.end(), + std::deque >(), + AccRequestGroup(op)); + groups.insert(groups.end(), remGroups.begin(), remGroups.end()); } return MultiUrlRequestInfo(groups, op, getStatCalc(op), getSummaryOut(op)).execute(); }