From 2462a3b06cd54b0b0534dc7c133b382e498266f2 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 22 Feb 2006 14:30:47 +0000 Subject: [PATCH] --- ChangeLog | 9 +++++++ TODO | 3 +-- src/DownloadCommand.cc | 19 ++++++++++++++- src/DownloadCommand.h | 3 +++ src/FtpConnection.cc | 2 +- src/Makefile.am | 3 +++ src/Makefile.in | 55 ++++++++++++++++++++++++++++++++++++++++-- src/Segment.h | 7 ++++++ src/SegmentMan.cc | 31 ++---------------------- src/SegmentMan.h | 4 ++- src/Util.h | 2 +- src/main.cc | 9 +++++-- 12 files changed, 108 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index af586269..7678a435 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2006-02-22 Tatsuhiro Tsujikawa + * SplitSlowestSegmentSplitter.{h,cc}: This class provies algorithm + that splits slowest segment of SegmentMan::commands vector. + This is the default split algorithm of aria2. + * SplitFirstSegmentSplitter.{h,cc}: This class provides algorithm + that splits first segment of SegmentMan::commands vector. + * SegmentSplitter.{h,cc}: Added. This class provides split algorithm. + * DownloadCommand.{h,cc}: Added downloading speed calculation. + * Segment.h: + * SegmentMan.cc: Added speed field to Segment.h * main.cc: -s option now affects all URLs in command-line arguemtns. * HttpResponseCommand.cc: Fixed bug that segment file is not loaded. * message.h: Change file size related %d to %lld. diff --git a/TODO b/TODO index e8c1e273..e05708c1 100644 --- a/TODO +++ b/TODO @@ -5,5 +5,4 @@ * Better HTTP status handling * Download files listed in a specifed file. * check MD5 checksum -* Apply "split longest remianing time first" algorithm to SegmentMan. -* split algorithm must be separate class. \ No newline at end of file +* Add the feature which adds or removes URLs on-the-fly. \ No newline at end of file diff --git a/src/DownloadCommand.cc b/src/DownloadCommand.cc index 0cc15661..b771cbe5 100644 --- a/src/DownloadCommand.cc +++ b/src/DownloadCommand.cc @@ -27,7 +27,10 @@ #include "InitiateConnectionCommandFactory.h" #include "message.h" -DownloadCommand::DownloadCommand(int cuid, Request* req, DownloadEngine* e, Socket* s):AbstractCommand(cuid, req, e, s) {} +DownloadCommand::DownloadCommand(int cuid, Request* req, DownloadEngine* e, Socket* s):AbstractCommand(cuid, req, e, s), lastSize(0) { + sw.tv_sec = 0; + sw.tv_usec = 0; +} DownloadCommand::~DownloadCommand() {} @@ -50,6 +53,20 @@ bool DownloadCommand::executeInternal(Segment seg) { e->diskWriter->writeData(buf, bufSize, seg.sp+seg.ds); seg.ds += bufSize; } + // calculate downloading speed + struct timeval now; + gettimeofday(&now, NULL); + if(sw.tv_sec == 0 && sw.tv_usec == 0) { + sw = now; + lastSize = seg.ds; + } else { + long long int diff = Util::difftv(now, sw); + if(diff >= 1000000) { + seg.speed = (int)((seg.ds-lastSize)/(diff/1000000.0)); + sw = now; + lastSize = seg.ds; + } + } if(te != NULL && te->finished() || te == NULL && seg.ds >= seg.ep-seg.sp+1 diff --git a/src/DownloadCommand.h b/src/DownloadCommand.h index af44901c..3dd374e7 100644 --- a/src/DownloadCommand.h +++ b/src/DownloadCommand.h @@ -29,6 +29,9 @@ using namespace std; class DownloadCommand : public AbstractCommand { +private: + struct timeval sw; + long long int lastSize; protected: bool executeInternal(Segment segment); diff --git a/src/FtpConnection.cc b/src/FtpConnection.cc index 54844e74..9e7b9d44 100644 --- a/src/FtpConnection.cc +++ b/src/FtpConnection.cc @@ -113,7 +113,7 @@ int FtpConnection::getStatus(string response) const { // When the response is not like "%d %*s", // we return 0. if(response.find_first_not_of("0123456789") != 3 - || response.find(" ") != 3) { + || !(response.find(" ") == 3 || response.find("-") == 3)) { return 0; } if(sscanf(response.c_str(), "%d %*s", &status) == 1) { diff --git a/src/Makefile.am b/src/Makefile.am index 4ae30cca..796cdd82 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,6 +24,9 @@ SRCS = Socket.cc Socket.h\ DownloadEngine.cc DownloadEngine.h\ Segment.h\ SegmentMan.cc SegmentMan.h\ + SegmentSplitter.cc SegmentSplitter.h\ + SplitFirstSegmentSplitter.cc SplitFirstSegmentSplitter.h\ + SplitSlowestSegmentSplitter.cc SplitSlowestSegmentSplitter.h\ Util.cc Util.h\ Request.cc Request.h\ common.h\ diff --git a/src/Makefile.in b/src/Makefile.in index 760a3bce..51f4454a 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -71,8 +71,11 @@ am__objects_1 = libaria2c_a-Socket.$(OBJEXT) \ libaria2c_a-FtpTunnelResponseCommand.$(OBJEXT) \ libaria2c_a-SleepCommand.$(OBJEXT) \ libaria2c_a-DownloadEngine.$(OBJEXT) \ - libaria2c_a-SegmentMan.$(OBJEXT) libaria2c_a-Util.$(OBJEXT) \ - libaria2c_a-Request.$(OBJEXT) \ + libaria2c_a-SegmentMan.$(OBJEXT) \ + libaria2c_a-SegmentSplitter.$(OBJEXT) \ + libaria2c_a-SplitFirstSegmentSplitter.$(OBJEXT) \ + libaria2c_a-SplitSlowestSegmentSplitter.$(OBJEXT) \ + libaria2c_a-Util.$(OBJEXT) libaria2c_a-Request.$(OBJEXT) \ libaria2c_a-SimpleLogger.$(OBJEXT) \ libaria2c_a-ChunkedEncoding.$(OBJEXT) \ libaria2c_a-DefaultDiskWriter.$(OBJEXT) \ @@ -211,6 +214,9 @@ SRCS = Socket.cc Socket.h\ DownloadEngine.cc DownloadEngine.h\ Segment.h\ SegmentMan.cc SegmentMan.h\ + SegmentSplitter.cc SegmentSplitter.h\ + SplitFirstSegmentSplitter.cc SplitFirstSegmentSplitter.h\ + SplitSlowestSegmentSplitter.cc SplitSlowestSegmentSplitter.h\ Util.cc Util.h\ Request.cc Request.h\ common.h\ @@ -337,10 +343,13 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libaria2c_a-Option.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libaria2c_a-Request.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libaria2c_a-SegmentMan.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libaria2c_a-SegmentSplitter.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libaria2c_a-SimpleLogger.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libaria2c_a-SleepCommand.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libaria2c_a-Socket.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libaria2c_a-SocketCore.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libaria2c_a-SplitFirstSegmentSplitter.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libaria2c_a-SplitSlowestSegmentSplitter.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libaria2c_a-Util.Po@am__quote@ .cc.o: @@ -665,6 +674,48 @@ libaria2c_a-SegmentMan.obj: SegmentMan.cc @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libaria2c_a_CXXFLAGS) $(CXXFLAGS) -c -o libaria2c_a-SegmentMan.obj `if test -f 'SegmentMan.cc'; then $(CYGPATH_W) 'SegmentMan.cc'; else $(CYGPATH_W) '$(srcdir)/SegmentMan.cc'; fi` +libaria2c_a-SegmentSplitter.o: SegmentSplitter.cc +@am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libaria2c_a_CXXFLAGS) $(CXXFLAGS) -MT libaria2c_a-SegmentSplitter.o -MD -MP -MF "$(DEPDIR)/libaria2c_a-SegmentSplitter.Tpo" -c -o libaria2c_a-SegmentSplitter.o `test -f 'SegmentSplitter.cc' || echo '$(srcdir)/'`SegmentSplitter.cc; \ +@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/libaria2c_a-SegmentSplitter.Tpo" "$(DEPDIR)/libaria2c_a-SegmentSplitter.Po"; else rm -f "$(DEPDIR)/libaria2c_a-SegmentSplitter.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='SegmentSplitter.cc' object='libaria2c_a-SegmentSplitter.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libaria2c_a_CXXFLAGS) $(CXXFLAGS) -c -o libaria2c_a-SegmentSplitter.o `test -f 'SegmentSplitter.cc' || echo '$(srcdir)/'`SegmentSplitter.cc + +libaria2c_a-SegmentSplitter.obj: SegmentSplitter.cc +@am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libaria2c_a_CXXFLAGS) $(CXXFLAGS) -MT libaria2c_a-SegmentSplitter.obj -MD -MP -MF "$(DEPDIR)/libaria2c_a-SegmentSplitter.Tpo" -c -o libaria2c_a-SegmentSplitter.obj `if test -f 'SegmentSplitter.cc'; then $(CYGPATH_W) 'SegmentSplitter.cc'; else $(CYGPATH_W) '$(srcdir)/SegmentSplitter.cc'; fi`; \ +@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/libaria2c_a-SegmentSplitter.Tpo" "$(DEPDIR)/libaria2c_a-SegmentSplitter.Po"; else rm -f "$(DEPDIR)/libaria2c_a-SegmentSplitter.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='SegmentSplitter.cc' object='libaria2c_a-SegmentSplitter.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libaria2c_a_CXXFLAGS) $(CXXFLAGS) -c -o libaria2c_a-SegmentSplitter.obj `if test -f 'SegmentSplitter.cc'; then $(CYGPATH_W) 'SegmentSplitter.cc'; else $(CYGPATH_W) '$(srcdir)/SegmentSplitter.cc'; fi` + +libaria2c_a-SplitFirstSegmentSplitter.o: SplitFirstSegmentSplitter.cc +@am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libaria2c_a_CXXFLAGS) $(CXXFLAGS) -MT libaria2c_a-SplitFirstSegmentSplitter.o -MD -MP -MF "$(DEPDIR)/libaria2c_a-SplitFirstSegmentSplitter.Tpo" -c -o libaria2c_a-SplitFirstSegmentSplitter.o `test -f 'SplitFirstSegmentSplitter.cc' || echo '$(srcdir)/'`SplitFirstSegmentSplitter.cc; \ +@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/libaria2c_a-SplitFirstSegmentSplitter.Tpo" "$(DEPDIR)/libaria2c_a-SplitFirstSegmentSplitter.Po"; else rm -f "$(DEPDIR)/libaria2c_a-SplitFirstSegmentSplitter.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='SplitFirstSegmentSplitter.cc' object='libaria2c_a-SplitFirstSegmentSplitter.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libaria2c_a_CXXFLAGS) $(CXXFLAGS) -c -o libaria2c_a-SplitFirstSegmentSplitter.o `test -f 'SplitFirstSegmentSplitter.cc' || echo '$(srcdir)/'`SplitFirstSegmentSplitter.cc + +libaria2c_a-SplitFirstSegmentSplitter.obj: SplitFirstSegmentSplitter.cc +@am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libaria2c_a_CXXFLAGS) $(CXXFLAGS) -MT libaria2c_a-SplitFirstSegmentSplitter.obj -MD -MP -MF "$(DEPDIR)/libaria2c_a-SplitFirstSegmentSplitter.Tpo" -c -o libaria2c_a-SplitFirstSegmentSplitter.obj `if test -f 'SplitFirstSegmentSplitter.cc'; then $(CYGPATH_W) 'SplitFirstSegmentSplitter.cc'; else $(CYGPATH_W) '$(srcdir)/SplitFirstSegmentSplitter.cc'; fi`; \ +@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/libaria2c_a-SplitFirstSegmentSplitter.Tpo" "$(DEPDIR)/libaria2c_a-SplitFirstSegmentSplitter.Po"; else rm -f "$(DEPDIR)/libaria2c_a-SplitFirstSegmentSplitter.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='SplitFirstSegmentSplitter.cc' object='libaria2c_a-SplitFirstSegmentSplitter.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libaria2c_a_CXXFLAGS) $(CXXFLAGS) -c -o libaria2c_a-SplitFirstSegmentSplitter.obj `if test -f 'SplitFirstSegmentSplitter.cc'; then $(CYGPATH_W) 'SplitFirstSegmentSplitter.cc'; else $(CYGPATH_W) '$(srcdir)/SplitFirstSegmentSplitter.cc'; fi` + +libaria2c_a-SplitSlowestSegmentSplitter.o: SplitSlowestSegmentSplitter.cc +@am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libaria2c_a_CXXFLAGS) $(CXXFLAGS) -MT libaria2c_a-SplitSlowestSegmentSplitter.o -MD -MP -MF "$(DEPDIR)/libaria2c_a-SplitSlowestSegmentSplitter.Tpo" -c -o libaria2c_a-SplitSlowestSegmentSplitter.o `test -f 'SplitSlowestSegmentSplitter.cc' || echo '$(srcdir)/'`SplitSlowestSegmentSplitter.cc; \ +@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/libaria2c_a-SplitSlowestSegmentSplitter.Tpo" "$(DEPDIR)/libaria2c_a-SplitSlowestSegmentSplitter.Po"; else rm -f "$(DEPDIR)/libaria2c_a-SplitSlowestSegmentSplitter.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='SplitSlowestSegmentSplitter.cc' object='libaria2c_a-SplitSlowestSegmentSplitter.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libaria2c_a_CXXFLAGS) $(CXXFLAGS) -c -o libaria2c_a-SplitSlowestSegmentSplitter.o `test -f 'SplitSlowestSegmentSplitter.cc' || echo '$(srcdir)/'`SplitSlowestSegmentSplitter.cc + +libaria2c_a-SplitSlowestSegmentSplitter.obj: SplitSlowestSegmentSplitter.cc +@am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libaria2c_a_CXXFLAGS) $(CXXFLAGS) -MT libaria2c_a-SplitSlowestSegmentSplitter.obj -MD -MP -MF "$(DEPDIR)/libaria2c_a-SplitSlowestSegmentSplitter.Tpo" -c -o libaria2c_a-SplitSlowestSegmentSplitter.obj `if test -f 'SplitSlowestSegmentSplitter.cc'; then $(CYGPATH_W) 'SplitSlowestSegmentSplitter.cc'; else $(CYGPATH_W) '$(srcdir)/SplitSlowestSegmentSplitter.cc'; fi`; \ +@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/libaria2c_a-SplitSlowestSegmentSplitter.Tpo" "$(DEPDIR)/libaria2c_a-SplitSlowestSegmentSplitter.Po"; else rm -f "$(DEPDIR)/libaria2c_a-SplitSlowestSegmentSplitter.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='SplitSlowestSegmentSplitter.cc' object='libaria2c_a-SplitSlowestSegmentSplitter.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libaria2c_a_CXXFLAGS) $(CXXFLAGS) -c -o libaria2c_a-SplitSlowestSegmentSplitter.obj `if test -f 'SplitSlowestSegmentSplitter.cc'; then $(CYGPATH_W) 'SplitSlowestSegmentSplitter.cc'; else $(CYGPATH_W) '$(srcdir)/SplitSlowestSegmentSplitter.cc'; fi` + libaria2c_a-Util.o: Util.cc @am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libaria2c_a_CXXFLAGS) $(CXXFLAGS) -MT libaria2c_a-Util.o -MD -MP -MF "$(DEPDIR)/libaria2c_a-Util.Tpo" -c -o libaria2c_a-Util.o `test -f 'Util.cc' || echo '$(srcdir)/'`Util.cc; \ @am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/libaria2c_a-Util.Tpo" "$(DEPDIR)/libaria2c_a-Util.Po"; else rm -f "$(DEPDIR)/libaria2c_a-Util.Tpo"; exit 1; fi diff --git a/src/Segment.h b/src/Segment.h index c6c2b36c..035282ae 100644 --- a/src/Segment.h +++ b/src/Segment.h @@ -22,6 +22,10 @@ #ifndef _D_SEGMENT_H_ #define _D_SEGMENT_H_ +#include + +using namespace std; + /** * Segment represents a download segment. * sp, ep is a offset from a begining of a file. @@ -36,9 +40,12 @@ typedef struct { long long int sp; long long int ep; long long int ds; + int speed; bool finish; } Segment; +typedef vector Segments; + #define SEGMENT_EQUAL(X, Y) (X.cuid == Y.cuid && X.sp == Y.sp && X.ep == Y.ep && X.ds == Y.ds && X.finish == Y.finish ? true : false) #endif // _D_SEGMENT_H_ diff --git a/src/SegmentMan.cc b/src/SegmentMan.cc index 0089575a..8046bf7b 100644 --- a/src/SegmentMan.cc +++ b/src/SegmentMan.cc @@ -52,6 +52,7 @@ bool SegmentMan::getSegment(Segment& seg, int cuid) { seg.sp = 0; seg.ep = totalSize == 0 ? 0 : totalSize-1; seg.ds = 0; + seg.speed = 0; seg.finish = false; segments.push_back(seg); return true; @@ -81,35 +82,7 @@ bool SegmentMan::getSegment(Segment& seg, int cuid) { return true; } } - for(vector::iterator itr = segments.begin(); itr != segments.end(); itr++) { - Segment& s = *itr; - if(s.finish) { - continue; - } - if(s.ep-(s.sp+s.ds) > option->getAsLLInt(PREF_MIN_SEGMENT_SIZE)) { - long long int nep = (s.ep-(s.sp+s.ds))/2+(s.sp+s.ds); - //nseg = { cuid, nep+1, s.ep, 0, false }; - seg.cuid = cuid; - seg.sp = nep+1; - seg.ep = s.ep; - seg.ds = 0; - seg.finish = false; - s.ep = nep; - logger->debug("return new segment { " - "sp = "+Util::llitos(seg.sp)+", "+ - "ep = "+Util::llitos(seg.ep)+", " - "ds = "+Util::llitos(seg.ds)+" } to "+ - "cuid "+Util::llitos(cuid)); - logger->debug("update segment { " - "sp = "+Util::llitos(s.sp)+", "+ - "ep = "+Util::llitos(s.ep)+", " - "ds = "+Util::llitos(s.ds)+" } of "+ - "cuid "+Util::llitos(s.cuid)); - segments.push_back(seg); - return true; - } - } - return false; + return splitter->splitSegment(seg, cuid, segments); } void SegmentMan::updateSegment(const Segment& segment) { diff --git a/src/SegmentMan.h b/src/SegmentMan.h index 075453ff..970a4fd0 100644 --- a/src/SegmentMan.h +++ b/src/SegmentMan.h @@ -27,6 +27,7 @@ #include "Logger.h" #include "Segment.h" #include "Option.h" +#include "SegmentSplitter.h" using namespace std; @@ -64,7 +65,7 @@ public: /** * Holds segments. */ - vector segments; + Segments segments; /** * Respresents the file name of the downloaded file. * If the URL does not contain file name part(http://www.rednoah.com/, for @@ -83,6 +84,7 @@ public: const Logger* logger; const Option* option; + SegmentSplitter* splitter; SegmentMan(); ~SegmentMan(); diff --git a/src/Util.h b/src/Util.h index 0377234b..98bb116e 100644 --- a/src/Util.h +++ b/src/Util.h @@ -37,7 +37,7 @@ public: static string llitos(long long int value, bool comma = false); static string itos(int value, bool comma = false); /** - * Computes difference in milli second between tv1 and tv2, + * Computes difference in micro-seconds between tv1 and tv2, * assuming tv1 is newer than tv2. * If tv1 is older than tv2, then this method returns 0. */ diff --git a/src/main.cc b/src/main.cc index 1f08d4ba..4abad821 100644 --- a/src/main.cc +++ b/src/main.cc @@ -22,6 +22,7 @@ #include "HttpInitiateConnectionCommand.h" #include "DownloadEngine.h" #include "SegmentMan.h" +#include "SplitSlowestSegmentSplitter.h" #include "SimpleLogger.h" #include "common.h" #include "DefaultDiskWriter.h" @@ -106,7 +107,7 @@ void showUsage() { cout << " -l, --log=LOG The file path to store log. If '-' is specified," << endl; cout << " log is written to stdout." << endl; cout << " -D, --daemon Run as daemon." << endl; - cout << " -s, --split=N Download a file using s connections. s must be" << endl; + cout << " -s, --split=N Download a file using N connections. N must be" << endl; cout << " between 1 and 5. This option affects all URLs." << endl; cout << " Thus, aria2 connects to each URL with N connections." << endl; cout << " --retry-wait=SEC Set amount of time in second between requests" << endl; @@ -138,6 +139,7 @@ void showUsage() { cout << " -p, --ftp-pasv Use passive mode in FTP." << endl; cout << " --ftp-via-http-proxy=WAY Use HTTP proxy in FTP. WAY is either 'get' or" << endl; cout << " 'tunnel'." << endl; + cout << " Default: tunnel" << endl; cout << " -v, --version Print the version number and exit." << endl; cout << " -h, --help Print this message and exit." << endl; cout << endl; @@ -176,7 +178,6 @@ int main(int argc, char* argv[]) { op->put(PREF_FTP_USER, "anonymous"); op->put(PREF_FTP_PASSWD, "ARIA2USER@"); op->put(PREF_FTP_TYPE, V_BINARY); - op->put(PREF_FTP_PASV_ENABLED, V_TRUE); op->put(PREF_FTP_VIA_HTTP_PROXY, V_TUNNEL); while(1) { @@ -393,6 +394,9 @@ int main(int argc, char* argv[]) { } else { logger = new SimpleLogger("/dev/null"); } + SegmentSplitter* splitter = new SplitSlowestSegmentSplitter(); + splitter->setMinSegmentSize(op->getAsLLInt(PREF_MIN_SEGMENT_SIZE)); + splitter->logger = logger; e = new DownloadEngine(); e->logger = logger; e->option = op; @@ -402,6 +406,7 @@ int main(int argc, char* argv[]) { e->segmentMan->ufilename = ufilename; e->segmentMan->logger = logger; e->segmentMan->option = op; + e->segmentMan->splitter = splitter; vector requests; for(int i = 1; optind+i-1 < argc; i++) { for(int s = 1; s <= split; s++) {