]> git.saurik.com Git - apt.git/blobdiff - methods/server.cc
Merge remote-tracking branch 'mvo/feature/expected-size' into debian/experimental
[apt.git] / methods / server.cc
index c91d3b21822f24c5a6515f548e65d290d4f60eb9..cef8097384526b5f430480196971a854ef45c44d 100644 (file)
@@ -44,7 +44,8 @@ time_t ServerMethod::FailTime = 0;
 // ---------------------------------------------------------------------
 /* Returns 0 if things are OK, 1 if an IO error occurred and 2 if a header
    parse error occurred */
 // ---------------------------------------------------------------------
 /* Returns 0 if things are OK, 1 if an IO error occurred and 2 if a header
    parse error occurred */
-ServerState::RunHeadersResult ServerState::RunHeaders(FileFd * const File)
+ServerState::RunHeadersResult ServerState::RunHeaders(FileFd * const File,
+                                                      const std::string &Uri)
 {
    State = Header;
    
 {
    State = Header;
    
@@ -66,7 +67,7 @@ ServerState::RunHeadersResult ServerState::RunHeaders(FileFd * const File)
         continue;
 
       if (Owner->Debug == true)
         continue;
 
       if (Owner->Debug == true)
-        clog << Data;
+        clog << "Answer for: " << Uri << endl << Data;
       
       for (string::const_iterator I = Data.begin(); I < Data.end(); ++I)
       {
       
       for (string::const_iterator I = Data.begin(); I < Data.end(); ++I)
       {
@@ -323,10 +324,10 @@ ServerMethod::DealWithHeaders(FetchResult &Res)
       failure */
    if (Server->Result < 200 || Server->Result >= 300)
    {
       failure */
    if (Server->Result < 200 || Server->Result >= 300)
    {
-      char err[255];
-      snprintf(err,sizeof(err)-1,"HttpError%i",Server->Result);
+      std::string err;
+      strprintf(err, "HttpError%u", Server->Result);
       SetFailReason(err);
       SetFailReason(err);
-      _error->Error("%u %s",Server->Result,Server->Code);
+      _error->Error("%u %s", Server->Result, Server->Code);
       if (Server->HaveContent == true)
         return ERROR_WITH_CONTENT_PAGE;
       return ERROR_UNRECOVERABLE;
       if (Server->HaveContent == true)
         return ERROR_WITH_CONTENT_PAGE;
       return ERROR_UNRECOVERABLE;
@@ -485,7 +486,7 @@ int ServerMethod::Loop()
       Fetch(0);
       
       // Fetch the next URL header data from the server.
       Fetch(0);
       
       // Fetch the next URL header data from the server.
-      switch (Server->RunHeaders(File))
+      switch (Server->RunHeaders(File, Queue->Uri))
       {
         case ServerState::RUN_HEADERS_OK:
         break;
       {
         case ServerState::RUN_HEADERS_OK:
         break;
@@ -531,6 +532,13 @@ int ServerMethod::Loop()
 
            // Run the data
            bool Result = true;
 
            // Run the data
            bool Result = true;
+
+            // ensure we don't fetch too much
+            // we could do "Server->MaximumSize = Queue->MaximumSize" here
+            // but that would break the clever pipeline messup detection
+            // so instead we use the size of the biggest item in the queue
+            Server->MaximumSize = FindMaximumObjectSizeInQueue();
+
             if (Server->HaveContent)
               Result = Server->RunData(File);
 
             if (Server->HaveContent)
               Result = Server->RunData(File);
 
@@ -604,7 +612,10 @@ int ServerMethod::Loop()
                  QueueBack = Queue;
               }
               else
                  QueueBack = Queue;
               }
               else
+               {
+                  Server->Close();
                  Fail(true);
                  Fail(true);
+               }
            }
            break;
         }
            }
            break;
         }
@@ -697,5 +708,15 @@ int ServerMethod::Loop()
    }
    
    return 0;
    }
    
    return 0;
+}
+                                                                       /*}}}*/
+                                                                       /*{{{*/
+unsigned long long
+ServerMethod::FindMaximumObjectSizeInQueue() const 
+{
+   unsigned long long MaxSizeInQueue = 0;
+   for (FetchItem *I = Queue->Next; I != 0 && I != QueueBack; I = I->Next)
+      MaxSizeInQueue = std::max(MaxSizeInQueue, I->MaximumSize);
+   return MaxSizeInQueue;
 }
                                                                        /*}}}*/
 }
                                                                        /*}}}*/