apt @VERSION@
|
A fetch subprocess. More...
#include <acquire-worker.h>
Public Member Functions | |
bool | QueueItem (pkgAcquire::Queue::QItem *Item) |
Tell the subprocess to download the given item. | |
bool | Start () |
Start up the worker and fill in Config. | |
void | Pulse () |
Update the worker statistics (CurrentSize, TotalSize, etc). | |
const MethodConfig * | GetConf () const |
Worker (Queue *OwnerQ, MethodConfig *Config, pkgAcquireStatus *Log) | |
Create a new Worker to download files. | |
Worker (MethodConfig *Config) | |
Create a new Worker that should just retrieve information about the fetch method. | |
~Worker () | |
Clean up this worker. | |
Public Attributes | |
pkgAcquire::Queue::QItem * | CurrentItem |
The queue entry that is currently being downloaded. | |
string | Status |
The most recent status string received from the subprocess. | |
unsigned long | CurrentSize |
How many bytes of the file have been downloaded. Zero if the current progress of the file cannot be determined. | |
unsigned long | TotalSize |
The total number of bytes to be downloaded. Zero if the total size of the final is unknown. | |
unsigned long | ResumePoint |
How much of the file was already downloaded prior to starting this worker. | |
Protected Member Functions | |
void | Construct () |
Common code for the constructor. | |
bool | ReadMessages () |
Retrieve any available messages from the subprocess. | |
bool | RunMessages () |
Parse and dispatch pending messages. | |
bool | InFdReady () |
Read and dispatch any pending messages from the subprocess. | |
bool | OutFdReady () |
Send any pending commands to the subprocess. | |
bool | Capabilities (string Message) |
Handle a 100 Capabilities response from the subprocess. | |
bool | SendConfiguration () |
Send a 601 Configuration message (containing the APT configuration) to the subprocess. | |
bool | MediaChange (string Message) |
Handle a 403 Media Change message. | |
bool | MethodFailure () |
Invoked when the worked process dies unexpectedly. | |
void | ItemDone () |
Invoked when a fetch job is completed, either successfully or unsuccessfully. | |
Protected Attributes | |
Worker * | NextQueue |
The next link on the Queue list. | |
Worker * | NextAcquire |
The next link on the Acquire list. | |
Queue * | OwnerQ |
The Queue with which this worker is associated. | |
pkgAcquireStatus * | Log |
The download progress indicator to which progress messages should be sent. | |
MethodConfig * | Config |
The configuration of this method. On startup, the target of this pointer is filled in with basic data about the method, as reported by the worker. | |
string | Access |
The access method to be used by this worker. | |
pid_t | Process |
The PID of the subprocess. | |
int | InFd |
A file descriptor connected to the standard output of the subprocess. | |
int | OutFd |
A file descriptor connected to the standard input of the subprocess. | |
bool | InReady |
Set to true if the worker is in a state in which it might generate data or command responses. | |
bool | OutReady |
Set to true if the worker is in a state in which it is legal to send commands to it. | |
bool | Debug |
vector< string > | MessageQueue |
The raw text values of messages received from the worker, in sequence. | |
string | OutQueue |
Buffers pending writes to the subprocess. | |
Friends | |
class | pkgAcquire |
class | Queue |
A fetch subprocess.
A worker process is responsible for one stage of the fetch. This class encapsulates the communications protocol between the master process and the worker, from the master end.
Each worker is intrinsically placed on two linked lists. The Queue list (maintained in the NextQueue variable) is maintained by the pkgAcquire::Queue class; it represents the set of workers assigned to a particular queue. The Acquire list (maintained in the NextAcquire variable) is maintained by the pkgAcquire class; it represents the set of active workers for a particular pkgAcquire object.
Worker | ( | Queue * | OwnerQ, |
MethodConfig * | Config, | ||
pkgAcquireStatus * | Log | ||
) |
Create a new Worker to download files.
OwnerQ | The queue into which this worker should be placed. |
Config | A location in which to store information about the fetch method. |
Log | The download progress indicator that should be used to report the progress of this worker. |
References pkgAcquire::MethodConfig::Access, Access, Config, Construct(), CurrentItem, CurrentSize, OwnerQ, and TotalSize.
Worker | ( | MethodConfig * | Config | ) |
Create a new Worker that should just retrieve information about the fetch method.
Nothing in particular forces you to refrain from actually downloading stuff, but the various status callbacks won't be invoked.
Config | A location in which to store information about the fetch method. |
References pkgAcquire::MethodConfig::Access.
~Worker | ( | ) |
Clean up this worker.
Closes the file descriptors; if MethodConfig::NeedsCleanup is false, also rudely interrupts the worker with a SIGINT.
bool Capabilities | ( | string | Message | ) | [protected] |
Handle a 100 Capabilities response from the subprocess.
Message | the raw text of the message from the subprocess. |
The message will be parsed and its contents used to fill Config. If Config is NULL, this routine is a NOP.
References pkgAcquire::Debug.
void Construct | ( | ) | [protected] |
Common code for the constructor.
Initializes NextQueue and NextAcquire to NULL; Process, InFd, and OutFd to -1, OutReady and InReady to false, and Debug from _config.
References pkgAcquire::Debug.
Referenced by Worker().
const MethodConfig* GetConf | ( | ) | const [inline] |
References Config.
Referenced by pkgAcquire::Queue::Shutdown().
bool InFdReady | ( | ) | [protected] |
Read and dispatch any pending messages from the subprocess.
void ItemDone | ( | ) | [protected] |
Invoked when a fetch job is completed, either successfully or unsuccessfully.
Resets the status information for the worker process.
bool MediaChange | ( | string | Message | ) | [protected] |
Handle a 403 Media Change message.
Message | the raw text of the message; the Media field indicates what type of media should be changed, and the Drive field indicates where the media is located. |
Invokes pkgAcquireStatus::MediaChange(Media, Drive) to ask the user to swap disks; informs the subprocess of the result (via 603 Media Changed, with the Failed field set to true if the user cancelled the media change).
bool MethodFailure | ( | ) | [protected] |
Invoked when the worked process dies unexpectedly.
Waits for the subprocess to terminate and generates an error if it terminated abnormally, then closes and blanks out all file descriptors. Discards all pending messages from the subprocess.
bool OutFdReady | ( | ) | [protected] |
Send any pending commands to the subprocess.
This method will fail if there is no pending output.
bool QueueItem | ( | pkgAcquire::Queue::QItem * | Item | ) |
Tell the subprocess to download the given item.
Item | the item to queue up. |
Queues up a 600 URI Acquire message for the given item to be sent at the next possible moment. Does not flush the output queue.
References pkgAcquire::Item::Custom600Headers(), pkgAcquire::Debug, pkgAcquire::Item::DestFile, pkgAcquire::ItemDesc::Owner, and pkgAcquire::ItemDesc::URI.
Referenced by pkgAcquire::Queue::Cycle().
bool ReadMessages | ( | ) | [protected] |
Retrieve any available messages from the subprocess.
The messages are retrieved as in ::ReadMessages(), and MessageFailure() is invoked if an error occurs; in particular, if the pipe to the subprocess dies unexpectedly while a message is being read.
bool RunMessages | ( | ) | [protected] |
Parse and dispatch pending messages.
This dispatches the message in a manner appropriate for its type.
References pkgAcquire::Debug, pkgAcquire::ItemDesc::Description, pkgAcquire::Item::DescURI(), pkgAcquireStatus::Done(), pkgAcquire::Item::Done(), pkgAcquireStatus::Fail(), pkgAcquire::Item::Failed(), pkgAcquireStatus::Fetch(), pkgAcquire::Item::GetOwner(), pkgAcquire::Item::HashSum(), pkgAcquireStatus::IMSHit(), pkgAcquire::Log, pkgAcquireStatus::MorePulses, pkgAcquire::ItemDesc::Owner, pkgAcquireStatus::Pulse(), pkgAcquire::Item::Start(), pkgAcquire::Item::StatTransientNetworkError, and pkgAcquire::ItemDesc::URI.
bool SendConfiguration | ( | ) | [protected] |
Send a 601 Configuration message (containing the APT configuration) to the subprocess.
The APT configuration will be send to the subprocess in a message of the following form:
601 Configuration Config-Item: Fully-Qualified-Item=Val Config-Item: Fully-Qualified-Item=Val ...
References pkgAcquire::Debug.
bool Start | ( | ) |
Start up the worker and fill in Config.
Reads the first message from the worker, which is assumed to be a 100 Capabilities message.
References pkgAcquire::Debug.
Referenced by pkgAcquire::GetConfig(), and pkgAcquire::Queue::Startup().
string Access [protected] |
bool Debug [protected] |
If true, debugging output will be sent to std::clog.
int InFd [protected] |
A file descriptor connected to the standard output of the subprocess.
Used to read messages and data from the subprocess.
bool InReady [protected] |
Set to true if the worker is in a state in which it might generate data or command responses.
The next link on the Queue list.
Referenced by pkgAcquire::Queue::Shutdown().
int OutFd [protected] |
A file descriptor connected to the standard input of the subprocess.
Used to send commands and configuration data to the subprocess.
string OutQueue [protected] |
Buffers pending writes to the subprocess.
bool OutReady [protected] |
Set to true if the worker is in a state in which it is legal to send commands to it.