Pārlūkot izejas kodu

2010-10-19 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Don't reuse socket which is readable because we assume that if
	socket is readable it means peer shutdowns connection and the
	socket will receive EOF. Added default timeout value to
	DownloadEngine::poolSocket().
	* src/DownloadEngine.cc
	* src/DownloadEngine.h
Tatsuhiro Tsujikawa 15 gadi atpakaļ
vecāks
revīzija
51308002d3
3 mainītis faili ar 14 papildinājumiem un 3 dzēšanām
  1. 9 0
      ChangeLog
  2. 3 1
      src/DownloadEngine.cc
  3. 2 2
      src/DownloadEngine.h

+ 9 - 0
ChangeLog

@@ -1,3 +1,12 @@
+2010-10-19  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Don't reuse socket which is readable because we assume that if
+	socket is readable it means peer shutdowns connection and the
+	socket will receive EOF. Added default timeout value to
+	DownloadEngine::poolSocket().
+	* src/DownloadEngine.cc
+	* src/DownloadEngine.h
+
 2010-10-19  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Fixed the bug that file allocation is enabled in HTTP even if

+ 3 - 1
src/DownloadEngine.cc

@@ -399,7 +399,9 @@ DownloadEngine::findSocketPoolEntry(const std::string& key)
   for(std::multimap<std::string, SocketPoolEntry>::iterator i =
         range.first, eoi = range.second; i != eoi; ++i) {
     const SocketPoolEntry& e = (*i).second;
-    if(!e.isTimeout()) {
+    // We assume that if socket is readable it means peer shutdowns
+    // connection and the socket will receive EOF. So skip it.
+    if(!e.isTimeout() && !e.getSocket()->isReadable(0)) {
       logger_->info("Found socket for %s", key.c_str());
       return i;
     }

+ 2 - 2
src/DownloadEngine.h

@@ -257,7 +257,7 @@ public:
                   const std::string& proxyhost, uint16_t proxyport,
                   const SharedHandle<SocketCore>& sock,
                   const std::map<std::string, std::string>& options,
-                  time_t timeout);
+                  time_t timeout = 15);
 
   void poolSocket(const SharedHandle<Request>& request,
                   const std::string& username,
@@ -269,7 +269,7 @@ public:
   void poolSocket(const std::string& ipaddr, uint16_t port,
                   const std::string& proxyhost, uint16_t proxyport,
                   const SharedHandle<SocketCore>& sock,
-                  time_t timeout);
+                  time_t timeout = 15);
 
   void poolSocket(const SharedHandle<Request>& request,
                   const SharedHandle<Request>& proxyRequest,