Ver código fonte

2008-04-26 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	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
Tatsuhiro Tsujikawa 17 anos atrás
pai
commit
a7952cce05
2 arquivos alterados com 46 adições e 3 exclusões
  1. 23 0
      ChangeLog
  2. 23 3
      src/main.cc

+ 23 - 0
ChangeLog

@@ -1,3 +1,26 @@
+2008-04-26  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	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  <tujikawa at rednoah dot com>
 
 	Fixed the bug that causes segmentaion fault when reading XML containing

+ 23 - 3
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<std::string>& uris)
 {
   std::deque<std::string> nargs;
@@ -307,11 +316,22 @@ int32_t downloadUri(Option* op, const std::deque<std::string>& uris)
 			     std::deque<SharedHandle<RequestGroup> >(),
 			     AccRequestGroup(op));
   } else {
+    std::deque<std::string>::iterator strmProtoEnd =
+      std::stable_partition(nargs.begin(), nargs.end(), StreamProtocolFilter());
+    // let's process http/ftp protocols first.
     std::deque<std::string> 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<SharedHandle<RequestGroup> > remGroups =
+      std::accumulate(strmProtoEnd, nargs.end(),
+		      std::deque<SharedHandle<RequestGroup> >(),
+		      AccRequestGroup(op));
+    groups.insert(groups.end(), remGroups.begin(), remGroups.end());
   }
   return MultiUrlRequestInfo(groups, op, getStatCalc(op), getSummaryOut(op)).execute();
 }