Browse Source

2009-02-01 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Applied AdaptiveURISelector-timeout patch from Pascal Rigaux at
	Mandriva. I modified the patch: make RequestGroup have the
	timeout value and AdaptiveURISelector directly modifies that
	value.
	* src/AbstractCommand.cc
	* src/AdaptiveURISelector.cc
	* src/AdaptiveURISelector.h
	* src/FtpNegotiationCommand.cc
	* src/RequestGroup.cc
	* src/RequestGroup.h
Tatsuhiro Tsujikawa 17 years ago
parent
commit
f16fb1c890

+ 13 - 0
ChangeLog

@@ -1,3 +1,16 @@
+2009-02-01  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Applied AdaptiveURISelector-timeout patch from Pascal Rigaux at
+	Mandriva. I modified the patch: make RequestGroup have the
+	timeout value and AdaptiveURISelector directly modifies that
+	value.
+	* src/AbstractCommand.cc
+	* src/AdaptiveURISelector.cc
+	* src/AdaptiveURISelector.h
+	* src/FtpNegotiationCommand.cc
+	* src/RequestGroup.cc
+	* src/RequestGroup.h
+
 2009-02-01  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Fixed compiler warning

+ 1 - 1
src/AbstractCommand.cc

@@ -78,7 +78,7 @@ AbstractCommand::AbstractCommand(int32_t cuid,
   if(!socket.isNull() && socket->isOpen()) {
     setReadCheckSocket(socket);
   }
-  timeout = this->e->option->getAsInt(PREF_TIMEOUT);
+  timeout = _requestGroup->getTimeout();
   _requestGroup->increaseStreamConnection();
 }
 

+ 29 - 0
src/AdaptiveURISelector.cc

@@ -76,6 +76,14 @@ AdaptiveURISelector::~AdaptiveURISelector() {}
 
 std::string AdaptiveURISelector::select(std::deque<std::string>& uris)
 {
+  _logger->debug("AdaptiveURISelector: called %d",
+		 _requestGroup->getNumConnection());
+  if (uris.empty() && _requestGroup->getNumConnection() <= 1) {
+    // here we know the download will fail, trying to find previously
+    // failed uris that may succeed with more permissive values
+    mayRetryWithIncreasedTimeout(uris);
+  }
+ 
   std::string selected = selectOne(uris);
 
   if(selected != A2STR::NIL)
@@ -84,6 +92,27 @@ std::string AdaptiveURISelector::select(std::deque<std::string>& uris)
   return selected;
 }
 
+void AdaptiveURISelector::mayRetryWithIncreasedTimeout
+(std::deque<std::string>& uris)
+{
+  if (_requestGroup->getTimeout()*2 >= MAX_TIMEOUT) return;
+  _requestGroup->setTimeout(_requestGroup->getTimeout()*2);
+
+  // looking for retries
+  const std::deque<URIResult>& uriResults = _requestGroup->getURIResults();
+  for (std::deque<URIResult>::const_iterator i = uriResults.begin();
+       i != uriResults.end(); ++i) {
+    if ((*i).getResult() == DownloadResult::TIME_OUT) {
+      _logger->debug("AdaptiveURISelector: will retry server with increased"
+		     " timeout (%d s): %s",
+		     _requestGroup->getTimeout(), (*i).getURI().c_str());
+      uris.push_back((*i).getURI());
+    }
+  }
+  std::sort(uris.begin(), uris.end());
+  uris.erase(std::unique(uris.begin(), uris.end()), uris.end());
+}
+
 std::string AdaptiveURISelector::selectOne(const std::deque<std::string>& uris)
 {
 

+ 4 - 0
src/AdaptiveURISelector.h

@@ -52,8 +52,12 @@ private:
   unsigned int _nbServerToEvaluate;
   unsigned int _nbConnections;
 
+  static const unsigned int MAX_TIMEOUT = 60;
+
   Logger* _logger;
 
+  void mayRetryWithIncreasedTimeout(std::deque<std::string>& uris);
+
   std::string selectOne(const std::deque<std::string>& uris);
   void adjustLowestSpeedLimit(const std::deque<std::string>& uris,
 			      DownloadCommand* command) const;

+ 1 - 1
src/FtpNegotiationCommand.cc

@@ -126,7 +126,7 @@ bool FtpNegotiationCommand::executeInternal() {
 
 bool FtpNegotiationCommand::recvGreeting() {
   checkIfConnectionEstablished(socket);
-  setTimeout(e->option->getAsInt(PREF_TIMEOUT));
+  setTimeout(_requestGroup->getTimeout());
   //socket->setBlockingMode();
   disableWriteCheckSocket();
   setReadCheckSocket(socket);

+ 12 - 1
src/RequestGroup.cc

@@ -126,6 +126,7 @@ RequestGroup::RequestGroup(const Option* option,
   _uriSelector(new InOrderURISelector()),
   _lastModifiedTime(Time::null()),
   _fileNotFoundCount(0),
+  _timeout(option->getAsInt(PREF_TIMEOUT)),
   _inMemoryDownload(false),
   _option(option),
   _logger(LogFactory::getInstance())
@@ -546,7 +547,7 @@ void RequestGroup::createNextCommand(std::deque<Command*>& commands,
 				     const std::string& method)
 {
   std::deque<std::string> pendingURIs;
-  for(; !_uris.empty() && numCommand--; ) {    
+  for(; numCommand--; ) {    
     std::string uri = _uriSelector->select(_uris);
     if(uri.empty())
       continue;
@@ -1133,4 +1134,14 @@ const std::deque<URIResult>& RequestGroup::getURIResults() const
   return _uriResults;
 }
 
+void RequestGroup::setTimeout(time_t timeout)
+{
+  _timeout = timeout;
+}
+
+time_t RequestGroup::getTimeout() const
+{
+  return _timeout;
+}
+
 } // namespace aria2

+ 7 - 0
src/RequestGroup.h

@@ -134,6 +134,9 @@ private:
 
   unsigned int _fileNotFoundCount;
 
+  // Timeout used for HTTP/FTP downloads.
+  time_t _timeout;
+
 #ifdef ENABLE_BITTORRENT
   WeakHandle<BtRuntime> _btRuntime;
 
@@ -424,6 +427,10 @@ public:
   bool inMemoryDownload() const;
 
   void tuneDownloadCommand(DownloadCommand* command);
+
+  void setTimeout(time_t timeout);
+
+  time_t getTimeout() const;
 };
 
 typedef SharedHandle<RequestGroup> RequestGroupHandle;