acquire.cc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: acquire.cc,v 1.14 1998/11/12 04:10:54 jgg Exp $
  4. /* ######################################################################
  5. Acquire - File Acquiration
  6. The core element for the schedual system is the concept of a named
  7. queue. Each queue is unique and each queue has a name derived from the
  8. URI. The degree of paralization can be controled by how the queue
  9. name is derived from the URI.
  10. ##################################################################### */
  11. /*}}}*/
  12. // Include Files /*{{{*/
  13. #ifdef __GNUG__
  14. #pragma implementation "apt-pkg/acquire.h"
  15. #endif
  16. #include <apt-pkg/acquire.h>
  17. #include <apt-pkg/acquire-item.h>
  18. #include <apt-pkg/acquire-worker.h>
  19. #include <apt-pkg/configuration.h>
  20. #include <apt-pkg/error.h>
  21. #include <strutl.h>
  22. #include <dirent.h>
  23. #include <sys/time.h>
  24. /*}}}*/
  25. // Acquire::pkgAcquire - Constructor /*{{{*/
  26. // ---------------------------------------------------------------------
  27. /* We grab some runtime state from the configuration space */
  28. pkgAcquire::pkgAcquire(pkgAcquireStatus *Log) : Log(Log)
  29. {
  30. Queues = 0;
  31. Configs = 0;
  32. Workers = 0;
  33. ToFetch = 0;
  34. Running = false;
  35. string Mode = _config->Find("Acquire::Queue-Mode","host");
  36. if (strcasecmp(Mode.c_str(),"host") == 0)
  37. QueueMode = QueueHost;
  38. if (strcasecmp(Mode.c_str(),"access") == 0)
  39. QueueMode = QueueAccess;
  40. Debug = _config->FindB("Debug::pkgAcquire",false);
  41. }
  42. /*}}}*/
  43. // Acquire::~pkgAcquire - Destructor /*{{{*/
  44. // ---------------------------------------------------------------------
  45. /* Free our memory, clean up the queues (destroy the workers) */
  46. pkgAcquire::~pkgAcquire()
  47. {
  48. while (Items.size() != 0)
  49. delete Items[0];
  50. while (Configs != 0)
  51. {
  52. MethodConfig *Jnk = Configs;
  53. Configs = Configs->Next;
  54. delete Jnk;
  55. }
  56. while (Queues != 0)
  57. {
  58. Queue *Jnk = Queues;
  59. Queues = Queues->Next;
  60. delete Jnk;
  61. }
  62. }
  63. /*}}}*/
  64. // Acquire::Add - Add a new item /*{{{*/
  65. // ---------------------------------------------------------------------
  66. /* This puts an item on the acquire list. This list is mainly for tracking
  67. item status */
  68. void pkgAcquire::Add(Item *Itm)
  69. {
  70. Items.push_back(Itm);
  71. }
  72. /*}}}*/
  73. // Acquire::Remove - Remove a item /*{{{*/
  74. // ---------------------------------------------------------------------
  75. /* Remove an item from the acquire list. This is usually not used.. */
  76. void pkgAcquire::Remove(Item *Itm)
  77. {
  78. for (vector<Item *>::iterator I = Items.begin(); I < Items.end(); I++)
  79. {
  80. if (*I == Itm)
  81. Items.erase(I);
  82. }
  83. }
  84. /*}}}*/
  85. // Acquire::Add - Add a worker /*{{{*/
  86. // ---------------------------------------------------------------------
  87. /* A list of workers is kept so that the select loop can direct their FD
  88. usage. */
  89. void pkgAcquire::Add(Worker *Work)
  90. {
  91. Work->NextAcquire = Workers;
  92. Workers = Work;
  93. }
  94. /*}}}*/
  95. // Acquire::Remove - Remove a worker /*{{{*/
  96. // ---------------------------------------------------------------------
  97. /* A worker has died. This can not be done while the select loop is running
  98. as it would require that RunFds could handling a changing list state and
  99. it cant.. */
  100. void pkgAcquire::Remove(Worker *Work)
  101. {
  102. if (Running == true)
  103. abort();
  104. Worker **I = &Workers;
  105. for (; *I != 0;)
  106. {
  107. if (*I == Work)
  108. *I = (*I)->NextAcquire;
  109. else
  110. I = &(*I)->NextAcquire;
  111. }
  112. }
  113. /*}}}*/
  114. // Acquire::Enqueue - Queue an URI for fetching /*{{{*/
  115. // ---------------------------------------------------------------------
  116. /* This is the entry point for an item. An item calls this function when
  117. it is construction which creates a queue (based on the current queue
  118. mode) and puts the item in that queue. If the system is running then
  119. the queue might be started. */
  120. void pkgAcquire::Enqueue(ItemDesc &Item)
  121. {
  122. // Determine which queue to put the item in
  123. string Name = QueueName(Item.URI);
  124. if (Name.empty() == true)
  125. return;
  126. // Find the queue structure
  127. Queue *I = Queues;
  128. for (; I != 0 && I->Name != Name; I = I->Next);
  129. if (I == 0)
  130. {
  131. I = new Queue(Name,this);
  132. I->Next = Queues;
  133. Queues = I;
  134. if (Running == true)
  135. I->Startup();
  136. }
  137. Item.Owner->Status = Item::StatIdle;
  138. // Queue it into the named queue
  139. I->Enqueue(Item);
  140. ToFetch++;
  141. // Some trace stuff
  142. if (Debug == true)
  143. {
  144. clog << "Fetching " << Item.URI << endl;
  145. clog << " to " << Item.Owner->DestFile << endl;
  146. clog << " Queue is: " << QueueName(Item.URI) << endl;
  147. }
  148. }
  149. /*}}}*/
  150. // Acquire::Dequeue - Remove an item from all queues /*{{{*/
  151. // ---------------------------------------------------------------------
  152. /* This is called when an item is finished being fetched. It removes it
  153. from all the queues */
  154. void pkgAcquire::Dequeue(Item *Itm)
  155. {
  156. Queue *I = Queues;
  157. bool Res = false;
  158. for (; I != 0; I = I->Next)
  159. Res |= I->Dequeue(Itm);
  160. if (Debug == true)
  161. clog << "Dequeuing " << Itm->DestFile << endl;
  162. if (Res == true)
  163. ToFetch--;
  164. }
  165. /*}}}*/
  166. // Acquire::QueueName - Return the name of the queue for this URI /*{{{*/
  167. // ---------------------------------------------------------------------
  168. /* The string returned depends on the configuration settings and the
  169. method parameters. Given something like http://foo.org/bar it can
  170. return http://foo.org or http */
  171. string pkgAcquire::QueueName(string Uri)
  172. {
  173. URI U(Uri);
  174. const MethodConfig *Config = GetConfig(U.Access);
  175. if (Config == 0)
  176. return string();
  177. /* Single-Instance methods get exactly one queue per URI. This is
  178. also used for the Access queue method */
  179. if (Config->SingleInstance == true || QueueMode == QueueAccess)
  180. return U.Access;
  181. return U.Access + ':' + U.Host;
  182. }
  183. /*}}}*/
  184. // Acquire::GetConfig - Fetch the configuration information /*{{{*/
  185. // ---------------------------------------------------------------------
  186. /* This locates the configuration structure for an access method. If
  187. a config structure cannot be found a Worker will be created to
  188. retrieve it */
  189. pkgAcquire::MethodConfig *pkgAcquire::GetConfig(string Access)
  190. {
  191. // Search for an existing config
  192. MethodConfig *Conf;
  193. for (Conf = Configs; Conf != 0; Conf = Conf->Next)
  194. if (Conf->Access == Access)
  195. return Conf;
  196. // Create the new config class
  197. Conf = new MethodConfig;
  198. Conf->Access = Access;
  199. Conf->Next = Configs;
  200. Configs = Conf;
  201. // Create the worker to fetch the configuration
  202. Worker Work(Conf);
  203. if (Work.Start() == false)
  204. return 0;
  205. return Conf;
  206. }
  207. /*}}}*/
  208. // Acquire::SetFds - Deal with readable FDs /*{{{*/
  209. // ---------------------------------------------------------------------
  210. /* Collect FDs that have activity monitors into the fd sets */
  211. void pkgAcquire::SetFds(int &Fd,fd_set *RSet,fd_set *WSet)
  212. {
  213. for (Worker *I = Workers; I != 0; I = I->NextAcquire)
  214. {
  215. if (I->InReady == true && I->InFd >= 0)
  216. {
  217. if (Fd < I->InFd)
  218. Fd = I->InFd;
  219. FD_SET(I->InFd,RSet);
  220. }
  221. if (I->OutReady == true && I->OutFd >= 0)
  222. {
  223. if (Fd < I->OutFd)
  224. Fd = I->OutFd;
  225. FD_SET(I->OutFd,WSet);
  226. }
  227. }
  228. }
  229. /*}}}*/
  230. // Acquire::RunFds - Deal with active FDs /*{{{*/
  231. // ---------------------------------------------------------------------
  232. /* Dispatch active FDs over to the proper workers. It is very important
  233. that a worker never be erased while this is running! The queue class
  234. should never erase a worker except during shutdown processing. */
  235. void pkgAcquire::RunFds(fd_set *RSet,fd_set *WSet)
  236. {
  237. for (Worker *I = Workers; I != 0; I = I->NextAcquire)
  238. {
  239. if (I->InFd >= 0 && FD_ISSET(I->InFd,RSet) != 0)
  240. I->InFdReady();
  241. if (I->OutFd >= 0 && FD_ISSET(I->OutFd,WSet) != 0)
  242. I->OutFdReady();
  243. }
  244. }
  245. /*}}}*/
  246. // Acquire::Run - Run the fetch sequence /*{{{*/
  247. // ---------------------------------------------------------------------
  248. /* This runs the queues. It manages a select loop for all of the
  249. Worker tasks. The workers interact with the queues and items to
  250. manage the actual fetch. */
  251. bool pkgAcquire::Run()
  252. {
  253. Running = true;
  254. for (Queue *I = Queues; I != 0; I = I->Next)
  255. I->Startup();
  256. if (Log != 0)
  257. Log->Start();
  258. // Run till all things have been acquired
  259. struct timeval tv;
  260. tv.tv_sec = 0;
  261. tv.tv_usec = 500000;
  262. while (ToFetch > 0)
  263. {
  264. fd_set RFds;
  265. fd_set WFds;
  266. int Highest = 0;
  267. FD_ZERO(&RFds);
  268. FD_ZERO(&WFds);
  269. SetFds(Highest,&RFds,&WFds);
  270. int Res = select(Highest+1,&RFds,&WFds,0,&tv);
  271. if (Res < 0)
  272. {
  273. _error->Errno("select","Select has failed");
  274. break;
  275. }
  276. RunFds(&RFds,&WFds);
  277. if (_error->PendingError() == true)
  278. break;
  279. // Timeout, notify the log class
  280. if (Res == 0 || (Log != 0 && Log->Update == true))
  281. {
  282. tv.tv_usec = 500000;
  283. for (Worker *I = Workers; I != 0; I = I->NextAcquire)
  284. I->Pulse();
  285. if (Log != 0)
  286. Log->Pulse(this);
  287. }
  288. }
  289. if (Log != 0)
  290. Log->Stop();
  291. // Shut down the acquire bits
  292. Running = false;
  293. for (Queue *I = Queues; I != 0; I = I->Next)
  294. I->Shutdown();
  295. return !_error->PendingError();
  296. }
  297. /*}}}*/
  298. // Acquire::Bump - Called when an item is dequeued /*{{{*/
  299. // ---------------------------------------------------------------------
  300. /* This routine bumps idle queues in hopes that they will be able to fetch
  301. the dequeued item */
  302. void pkgAcquire::Bump()
  303. {
  304. for (Queue *I = Queues; I != 0; I = I->Next)
  305. I->Bump();
  306. }
  307. /*}}}*/
  308. // Acquire::WorkerStep - Step to the next worker /*{{{*/
  309. // ---------------------------------------------------------------------
  310. /* Not inlined to advoid including acquire-worker.h */
  311. pkgAcquire::Worker *pkgAcquire::WorkerStep(Worker *I)
  312. {
  313. return I->NextAcquire;
  314. };
  315. /*}}}*/
  316. // pkgAcquire::Clean - Cleans a directory /*{{{*/
  317. // ---------------------------------------------------------------------
  318. /* This is a bit simplistic, it looks at every file in the dir and sees
  319. if it is part of the download set. */
  320. bool pkgAcquire::Clean(string Dir)
  321. {
  322. DIR *D = opendir(Dir.c_str());
  323. if (D == 0)
  324. return _error->Errno("opendir","Unable to read %s",Dir.c_str());
  325. string StartDir = SafeGetCWD();
  326. if (chdir(Dir.c_str()) != 0)
  327. {
  328. closedir(D);
  329. return _error->Errno("chdir","Unable to change to ",Dir.c_str());
  330. }
  331. for (struct dirent *Dir = readdir(D); Dir != 0; Dir = readdir(D))
  332. {
  333. // Skip some files..
  334. if (strcmp(Dir->d_name,"lock") == 0 ||
  335. strcmp(Dir->d_name,"partial") == 0 ||
  336. strcmp(Dir->d_name,".") == 0 ||
  337. strcmp(Dir->d_name,"..") == 0)
  338. continue;
  339. // Look in the get list
  340. vector<Item *>::iterator I = Items.begin();
  341. for (; I != Items.end(); I++)
  342. if (flNotDir((*I)->DestFile) == Dir->d_name)
  343. break;
  344. // Nothing found, nuke it
  345. if (I == Items.end())
  346. unlink(Dir->d_name);
  347. };
  348. chdir(StartDir.c_str());
  349. closedir(D);
  350. return true;
  351. }
  352. /*}}}*/
  353. // Acquire::MethodConfig::MethodConfig - Constructor /*{{{*/
  354. // ---------------------------------------------------------------------
  355. /* */
  356. pkgAcquire::MethodConfig::MethodConfig()
  357. {
  358. SingleInstance = false;
  359. PreScan = false;
  360. Pipeline = false;
  361. SendConfig = false;
  362. Next = 0;
  363. }
  364. /*}}}*/
  365. // Queue::Queue - Constructor /*{{{*/
  366. // ---------------------------------------------------------------------
  367. /* */
  368. pkgAcquire::Queue::Queue(string Name,pkgAcquire *Owner) : Name(Name),
  369. Owner(Owner)
  370. {
  371. Items = 0;
  372. Next = 0;
  373. Workers = 0;
  374. }
  375. /*}}}*/
  376. // Queue::~Queue - Destructor /*{{{*/
  377. // ---------------------------------------------------------------------
  378. /* */
  379. pkgAcquire::Queue::~Queue()
  380. {
  381. Shutdown();
  382. while (Items != 0)
  383. {
  384. QItem *Jnk = Items;
  385. Items = Items->Next;
  386. delete Jnk;
  387. }
  388. }
  389. /*}}}*/
  390. // Queue::Enqueue - Queue an item to the queue /*{{{*/
  391. // ---------------------------------------------------------------------
  392. /* */
  393. void pkgAcquire::Queue::Enqueue(ItemDesc &Item)
  394. {
  395. // Create a new item
  396. QItem *I = new QItem;
  397. I->Next = Items;
  398. Items = I;
  399. *I = Item;
  400. Item.Owner->QueueCounter++;
  401. if (Items->Next == 0)
  402. Cycle();
  403. }
  404. /*}}}*/
  405. // Queue::Dequeue - Remove an item from the queue /*{{{*/
  406. // ---------------------------------------------------------------------
  407. /* We return true if we hit something*/
  408. bool pkgAcquire::Queue::Dequeue(Item *Owner)
  409. {
  410. bool Res = false;
  411. QItem **I = &Items;
  412. for (; *I != 0;)
  413. {
  414. if ((*I)->Owner == Owner)
  415. {
  416. QItem *Jnk= *I;
  417. *I = (*I)->Next;
  418. Owner->QueueCounter--;
  419. delete Jnk;
  420. Res = true;
  421. }
  422. else
  423. I = &(*I)->Next;
  424. }
  425. return Res;
  426. }
  427. /*}}}*/
  428. // Queue::Startup - Start the worker processes /*{{{*/
  429. // ---------------------------------------------------------------------
  430. /* */
  431. bool pkgAcquire::Queue::Startup()
  432. {
  433. Shutdown();
  434. URI U(Name);
  435. pkgAcquire::MethodConfig *Cnf = Owner->GetConfig(U.Access);
  436. if (Cnf == 0)
  437. return false;
  438. Workers = new Worker(this,Cnf,Owner->Log);
  439. Owner->Add(Workers);
  440. if (Workers->Start() == false)
  441. return false;
  442. return Cycle();
  443. }
  444. /*}}}*/
  445. // Queue::Shutdown - Shutdown the worker processes /*{{{*/
  446. // ---------------------------------------------------------------------
  447. /* */
  448. bool pkgAcquire::Queue::Shutdown()
  449. {
  450. // Delete all of the workers
  451. while (Workers != 0)
  452. {
  453. pkgAcquire::Worker *Jnk = Workers;
  454. Workers = Workers->NextQueue;
  455. Owner->Remove(Jnk);
  456. delete Jnk;
  457. }
  458. return true;
  459. }
  460. /*}}}*/
  461. // Queue::Finditem - Find a URI in the item list /*{{{*/
  462. // ---------------------------------------------------------------------
  463. /* */
  464. pkgAcquire::Queue::QItem *pkgAcquire::Queue::FindItem(string URI,pkgAcquire::Worker *Owner)
  465. {
  466. for (QItem *I = Items; I != 0; I = I->Next)
  467. if (I->URI == URI && I->Worker == Owner)
  468. return I;
  469. return 0;
  470. }
  471. /*}}}*/
  472. // Queue::ItemDone - Item has been completed /*{{{*/
  473. // ---------------------------------------------------------------------
  474. /* The worker signals this which causes the item to be removed from the
  475. queue. If this is the last queue instance then it is removed from the
  476. main queue too.*/
  477. bool pkgAcquire::Queue::ItemDone(QItem *Itm)
  478. {
  479. if (Itm->Owner->QueueCounter <= 1)
  480. Owner->Dequeue(Itm->Owner);
  481. else
  482. {
  483. Dequeue(Itm->Owner);
  484. Owner->Bump();
  485. }
  486. return Cycle();
  487. }
  488. /*}}}*/
  489. // Queue::Cycle - Queue new items into the method /*{{{*/
  490. // ---------------------------------------------------------------------
  491. /* This locates a new idle item and sends it to the worker */
  492. bool pkgAcquire::Queue::Cycle()
  493. {
  494. if (Items == 0 || Workers == 0)
  495. return true;
  496. // Look for a queable item
  497. QItem *I = Items;
  498. for (; I != 0; I = I->Next)
  499. if (I->Owner->Status == pkgAcquire::Item::StatIdle)
  500. break;
  501. // Nothing to do, queue is idle.
  502. if (I == 0)
  503. return true;
  504. I->Worker = Workers;
  505. I->Owner->Status = pkgAcquire::Item::StatFetching;
  506. return Workers->QueueItem(I);
  507. }
  508. /*}}}*/
  509. // Queue::Bump - Fetch any pending objects if we are idle /*{{{*/
  510. // ---------------------------------------------------------------------
  511. /* */
  512. void pkgAcquire::Queue::Bump()
  513. {
  514. }
  515. /*}}}*/
  516. // AcquireStatus::pkgAcquireStatus - Constructor /*{{{*/
  517. // ---------------------------------------------------------------------
  518. /* */
  519. pkgAcquireStatus::pkgAcquireStatus()
  520. {
  521. Start();
  522. }
  523. /*}}}*/
  524. // AcquireStatus::Pulse - Called periodically /*{{{*/
  525. // ---------------------------------------------------------------------
  526. /* This computes some internal state variables for the derived classes to
  527. use. It generates the current downloaded bytes and total bytes to download
  528. as well as the current CPS estimate. */
  529. void pkgAcquireStatus::Pulse(pkgAcquire *Owner)
  530. {
  531. TotalBytes = 0;
  532. CurrentBytes = 0;
  533. // Compute the total number of bytes to fetch
  534. unsigned int Unknown = 0;
  535. unsigned int Count = 0;
  536. for (pkgAcquire::Item **I = Owner->ItemsBegin(); I != Owner->ItemsEnd();
  537. I++, Count++)
  538. {
  539. TotalBytes += (*I)->FileSize;
  540. if ((*I)->Complete == true)
  541. CurrentBytes += (*I)->FileSize;
  542. if ((*I)->FileSize == 0 && (*I)->Complete == false)
  543. Unknown++;
  544. }
  545. // Compute the current completion
  546. for (pkgAcquire::Worker *I = Owner->WorkersBegin(); I != 0;
  547. I = Owner->WorkerStep(I))
  548. if (I->CurrentItem != 0 && I->CurrentItem->Owner->Complete == false)
  549. CurrentBytes += I->CurrentSize;
  550. // Normalize the figures and account for unknown size downloads
  551. if (TotalBytes <= 0)
  552. TotalBytes = 1;
  553. if (Unknown == Count)
  554. TotalBytes = Unknown;
  555. else
  556. TotalBytes += TotalBytes/(Count - Unknown)*Unknown;
  557. // Compute the CPS
  558. struct timeval NewTime;
  559. gettimeofday(&NewTime,0);
  560. if (NewTime.tv_sec - Time.tv_sec == 6 && NewTime.tv_usec > Time.tv_usec ||
  561. NewTime.tv_sec - Time.tv_sec > 6)
  562. {
  563. // Compute the delta time with full accuracy
  564. long usdiff = NewTime.tv_usec - Time.tv_usec;
  565. long sdiff = NewTime.tv_sec - Time.tv_sec;
  566. // Borrow
  567. if (usdiff < 0)
  568. {
  569. usdiff += 1000000;
  570. sdiff--;
  571. }
  572. // Compute the CPS value
  573. CurrentCPS = (CurrentBytes - LastBytes)/(sdiff + usdiff/1000000.0);
  574. LastBytes = CurrentBytes;
  575. ElapsedTime = NewTime.tv_sec - StartTime.tv_sec;
  576. Time = NewTime;
  577. }
  578. }
  579. /*}}}*/
  580. // AcquireStatus::Start - Called when the download is started /*{{{*/
  581. // ---------------------------------------------------------------------
  582. /* We just reset the counters */
  583. void pkgAcquireStatus::Start()
  584. {
  585. gettimeofday(&Time,0);
  586. gettimeofday(&StartTime,0);
  587. LastBytes = 0;
  588. CurrentCPS = 0;
  589. CurrentBytes = 0;
  590. TotalBytes = 0;
  591. FetchedBytes = 0;
  592. ElapsedTime = 0;
  593. }
  594. /*}}}*/
  595. // pkgAcquireStatus::Stop - Finished downloading /*{{{*/
  596. // ---------------------------------------------------------------------
  597. /* This accurately computes the elapsed time and the total overall CPS. */
  598. void pkgAcquireStatus::Stop()
  599. {
  600. // Compute the CPS and elapsed time
  601. struct timeval NewTime;
  602. gettimeofday(&NewTime,0);
  603. // Compute the delta time with full accuracy
  604. long usdiff = NewTime.tv_usec - StartTime.tv_usec;
  605. long sdiff = NewTime.tv_sec - StartTime.tv_sec;
  606. // Borrow
  607. if (usdiff < 0)
  608. {
  609. usdiff += 1000000;
  610. sdiff--;
  611. }
  612. // Compute the CPS value
  613. CurrentCPS = FetchedBytes/(sdiff + usdiff/1000000.0);
  614. LastBytes = CurrentBytes;
  615. ElapsedTime = sdiff;
  616. }
  617. /*}}}*/
  618. // AcquireStatus::Fetched - Called when a byte set has been fetched /*{{{*/
  619. // ---------------------------------------------------------------------
  620. /* This is used to get accurate final transfer rate reporting. */
  621. void pkgAcquireStatus::Fetched(unsigned long Size,unsigned long Resume)
  622. {
  623. FetchedBytes += Size - Resume;
  624. }
  625. /*}}}*/