Bug#259688: libapt-pkg: make it possible to set select () timeout for pkgAcquire::Run
Package: apt
Version: 0.5.26
Severity: wishlist
Hello!
I am writing an libapt-pkg based frontend and i have ran into a slight
problem with pkgAcquire class. Because of the way i write it
(single-threaded), i need to get more pulses in my pkgAcquireStatus than
usual (about 5 - 10 a second).
One proposed solution is to add an optional parameter to Run (), with
a timeout to be used for select. An ABI-compatible patch is attached.
I somehow dislike this, as it's not the "right" solution for the given
problem...
The alternative solution would be to use the _config object to specify
the timeout and query it from within Run (), but i don't really like it.
On the other hand, this would allow the pkgAcquireStatus to change this
value instead of the caller of Run... Well, i'm not sure. A patch is
attached as well.
The best solution would be adding this timeout as a member variable, but
this is binary incompatible and thus probably infeasible right now.
(This way the pkgAcquireStatus would be able to set the Pulse interval,
which would be about ideal). I can make a patch if needed.
The preferred order is 3, 2, 1, but considering other factors, i think
#2 will be optimal for now. Other ways of fixing the problem would be
welcome though.
Thank you, yours,
Peter
-- System Information:
Debian Release: testing/unstable
APT prefers unstable
APT policy: (500, 'unstable'), (500, 'testing'), (1, 'experimental')
Architecture: i386 (i686)
Kernel: Linux 2.6.6-1-686
Locale: LANG=sk_SK.UTF-8, LC_CTYPE=sk_SK.UTF-8
Versions of packages apt depends on:
ii libc6 2.3.2.ds1-13 GNU C Library: Shared libraries an
ii libgcc1 1:3.3.4-2 GCC support library
ii libstdc++5 1:3.3.4-2 The GNU Standard C++ Library v3
-- no debconf information
diff -ruN apt-pkg.orig/acquire.cc apt-pkg/acquire.cc
--- apt-pkg.orig/acquire.cc 2004-03-17 06:17:11.000000000 +0100
+++ apt-pkg/acquire.cc 2004-07-16 08:06:50.000000000 +0200
@@ -314,6 +314,10 @@
manage the actual fetch. */
pkgAcquire::RunResult pkgAcquire::Run()
{
+ return Run (500000);
+}
+pkgAcquire::RunResult pkgAcquire::Run(int pulseUsec)
+{
Running = true;
for (Queue *I = Queues; I != 0; I = I->Next)
@@ -327,7 +331,7 @@
// Run till all things have been acquired
struct timeval tv;
tv.tv_sec = 0;
- tv.tv_usec = 500000;
+ tv.tv_usec = pulseUsec;
while (ToFetch > 0)
{
fd_set RFds;
@@ -357,7 +361,7 @@
// Timeout, notify the log class
if (Res == 0 || (Log != 0 && Log->Update == true))
{
- tv.tv_usec = 500000;
+ tv.tv_usec = pulseUsec;
for (Worker *I = Workers; I != 0; I = I->NextAcquire)
I->Pulse();
if (Log != 0 && Log->Pulse(this) == false)
diff -ruN apt-pkg.orig/acquire.h apt-pkg/acquire.h
--- apt-pkg.orig/acquire.h 2001-05-22 06:17:18.000000000 +0200
+++ apt-pkg/acquire.h 2004-07-16 08:04:27.000000000 +0200
@@ -101,6 +101,7 @@
enum RunResult {Continue,Failed,Cancelled};
RunResult Run();
+ RunResult Run(int PulseUsec);
void Shutdown();
// Simple iteration mechanism
diff -ruN apt-pkg.orig/acquire.cc apt-pkg/acquire.cc
--- apt-pkg.orig/acquire.cc 2004-03-17 06:17:11.000000000 +0100
+++ apt-pkg/acquire.cc 2004-07-16 08:40:34.000000000 +0200
@@ -22,6 +22,7 @@
#include <apt-pkg/configuration.h>
#include <apt-pkg/error.h>
#include <apt-pkg/strutl.h>
+#include <apt-pkg/configuration.h>
#include <apti18n.h>
@@ -327,7 +328,7 @@
// Run till all things have been acquired
struct timeval tv;
tv.tv_sec = 0;
- tv.tv_usec = 500000;
+ long tv_usec = tv.tv_usec = _config->FindI("APT::Fetcher::Select-Timeout-Usec", 500000);
while (ToFetch > 0)
{
fd_set RFds;
@@ -357,7 +358,7 @@
// Timeout, notify the log class
if (Res == 0 || (Log != 0 && Log->Update == true))
{
- tv.tv_usec = 500000;
+ tv.tv_usec = tv_usec;
for (Worker *I = Workers; I != 0; I = I->NextAcquire)
I->Pulse();
if (Log != 0 && Log->Pulse(this) == false)
Reply to: