]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/acquire.cc
HTTP pipelining
[apt.git] / apt-pkg / acquire.cc
index 9a546c7e204d829b9455665e6b1437ee0c454492..b7ef818a100596465c70cbffc07ceef3453ad9dd 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: acquire.cc,v 1.15 1998/11/13 07:08:54 jgg Exp $
+// $Id: acquire.cc,v 1.20 1998/12/05 04:19:03 jgg Exp $
 /* ######################################################################
 
    Acquire - File Acquiration
@@ -130,7 +130,8 @@ void pkgAcquire::Remove(Worker *Work)
 void pkgAcquire::Enqueue(ItemDesc &Item)
 {
    // Determine which queue to put the item in
-   string Name = QueueName(Item.URI);
+   const MethodConfig *Config;
+   string Name = QueueName(Item.URI,Config);
    if (Name.empty() == true)
       return;
 
@@ -147,6 +148,9 @@ void pkgAcquire::Enqueue(ItemDesc &Item)
         I->Startup();
    }
 
+   // See if this is a local only URI
+   if (Config->LocalOnly == true && Item.Owner->Complete == false)
+      Item.Owner->Local = true;
    Item.Owner->Status = Item::StatIdle;
    
    // Queue it into the named queue
@@ -158,7 +162,7 @@ void pkgAcquire::Enqueue(ItemDesc &Item)
    {
       clog << "Fetching " << Item.URI << endl;
       clog << " to " << Item.Owner->DestFile << endl;
-      clog << " Queue is: " << QueueName(Item.URI) << endl;
+      clog << " Queue is: " << Name << endl;
    }
 }
                                                                        /*}}}*/
@@ -184,11 +188,11 @@ void pkgAcquire::Dequeue(Item *Itm)
 /* The string returned depends on the configuration settings and the
    method parameters. Given something like http://foo.org/bar it can
    return http://foo.org or http */
-string pkgAcquire::QueueName(string Uri)
+string pkgAcquire::QueueName(string Uri,MethodConfig const *&Config)
 {
    URI U(Uri);
    
-   const MethodConfig *Config = GetConfig(U.Access);
+   Config = GetConfig(U.Access);
    if (Config == 0)
       return string();
    
@@ -386,18 +390,6 @@ bool pkgAcquire::Clean(string Dir)
    return true;   
 }
                                                                        /*}}}*/
-// Acquire::MethodConfig::MethodConfig - Constructor                   /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-pkgAcquire::MethodConfig::MethodConfig()
-{
-   SingleInstance = false;
-   PreScan = false;
-   Pipeline = false;
-   SendConfig = false;
-   Next = 0;
-}
-                                                                       /*}}}*/
 // Acquire::TotalNeeded - Number of bytes to fetch                     /*{{{*/
 // ---------------------------------------------------------------------
 /* This is the total number of bytes needed */
@@ -422,6 +414,19 @@ unsigned long pkgAcquire::FetchNeeded()
 }
                                                                        /*}}}*/
 
+// Acquire::MethodConfig::MethodConfig - Constructor                   /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+pkgAcquire::MethodConfig::MethodConfig()
+{
+   SingleInstance = false;
+   Pipeline = false;
+   SendConfig = false;
+   LocalOnly = false;
+   Next = 0;
+}
+                                                                       /*}}}*/
+
 // Queue::Queue - Constructor                                          /*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -453,11 +458,14 @@ pkgAcquire::Queue::~Queue()
 /* */
 void pkgAcquire::Queue::Enqueue(ItemDesc &Item)
 {
+   QItem **I = &Items;
+   for (; *I != 0; I = &(*I)->Next);
+   
    // Create a new item
-   QItem *I = new QItem;
-   I->Next = Items;
-   Items = I;
-   *I = Item;
+   QItem *Itm = new QItem;
+   *Itm = Item;
+   Itm->Next = 0;
+   *I = Itm;
    
    Item.Owner->QueueCounter++;   
    if (Items->Next == 0)
@@ -506,6 +514,17 @@ bool pkgAcquire::Queue::Startup()
    if (Workers->Start() == false)
       return false;
    
+   /* When pipelining we commit 10 items. This needs to change when we
+      added other source retry to have cycle maintain a pipeline depth
+      on its own. */
+   if (Cnf->Pipeline == true)
+   {
+      bool Res = true;
+      for (int I = 0; I != 10 && Res == true; I++)
+        Res &= Cycle();
+      return Res;
+   }
+   
    return Cycle();
 }
                                                                        /*}}}*/
@@ -603,6 +622,8 @@ void pkgAcquireStatus::Pulse(pkgAcquire *Owner)
 {
    TotalBytes = 0;
    CurrentBytes = 0;
+   TotalItems = 0;
+   CurrentItems = 0;
    
    // Compute the total number of bytes to fetch
    unsigned int Unknown = 0;
@@ -610,6 +631,10 @@ void pkgAcquireStatus::Pulse(pkgAcquire *Owner)
    for (pkgAcquire::Item **I = Owner->ItemsBegin(); I != Owner->ItemsEnd(); 
        I++, Count++)
    {
+      TotalItems++;
+      if ((*I)->Status == pkgAcquire::Item::StatDone)
+        CurrentItems++;
+      
       // Totally ignore local items
       if ((*I)->Local == true)
         continue;
@@ -653,7 +678,10 @@ void pkgAcquireStatus::Pulse(pkgAcquire *Owner)
       }
             
       // Compute the CPS value
-      CurrentCPS = (CurrentBytes - LastBytes)/(sdiff + usdiff/1000000.0);
+      if (sdiff == 0 && usdiff == 0)
+        CurrentCPS = 0;
+      else
+        CurrentCPS = (CurrentBytes - LastBytes)/(sdiff + usdiff/1000000.0);
       LastBytes = CurrentBytes;
       ElapsedTime = NewTime.tv_sec - StartTime.tv_sec;
       Time = NewTime;
@@ -673,6 +701,8 @@ void pkgAcquireStatus::Start()
    TotalBytes = 0;
    FetchedBytes = 0;
    ElapsedTime = 0;
+   TotalItems = 0;
+   CurrentItems = 0;
 }
                                                                        /*}}}*/
 // AcquireStatus::Stop - Finished downloading                          /*{{{*/
@@ -694,9 +724,12 @@ void pkgAcquireStatus::Stop()
       usdiff += 1000000;
       sdiff--;
    }
-   
+
    // Compute the CPS value
-   CurrentCPS = FetchedBytes/(sdiff + usdiff/1000000.0);
+   if (sdiff == 0 && usdiff == 0)
+      CurrentCPS = 0;
+   else
+      CurrentCPS = FetchedBytes/(sdiff + usdiff/1000000.0);
    LastBytes = CurrentBytes;
    ElapsedTime = sdiff;
 }