Skip to content

Commit 11b17b5

Browse files
committed
Auto merge of #6815 - ehuss:doc-downloads, r=Eh2406
Add some docs for `Downloads`. Rather than fight with rustfmt which didn't like the inline comment, I decided to just add some more elaborate docs.
2 parents c866f48 + aa8e257 commit 11b17b5

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

src/cargo/core/package.rs

+40-4
Original file line numberDiff line numberDiff line change
@@ -263,26 +263,49 @@ impl hash::Hash for Package {
263263
}
264264
}
265265

266+
/// A set of packages, with the intent to download.
267+
///
268+
/// This is primarily used to convert a set of `PackageId`s to `Package`s. It
269+
/// will download as needed, or used the cached download if available.
266270
pub struct PackageSet<'cfg> {
267271
packages: HashMap<PackageId, LazyCell<Package>>,
268272
sources: RefCell<SourceMap<'cfg>>,
269273
config: &'cfg Config,
270274
multi: Multi,
275+
/// Used to prevent reusing the PackageSet to download twice.
271276
downloading: Cell<bool>,
277+
/// Whether or not to use curl HTTP/2 multiplexing.
272278
multiplexing: bool,
273279
}
274280

281+
/// Helper for downloading crates.
275282
pub struct Downloads<'a, 'cfg: 'a> {
276283
set: &'a PackageSet<'cfg>,
284+
/// When a download is started, it is added to this map. The key is a
285+
/// "token" (see `Download::token`). It is removed once the download is
286+
/// finished.
277287
pending: HashMap<usize, (Download<'cfg>, EasyHandle)>,
288+
/// Set of packages currently being downloaded. This should stay in sync
289+
/// with `pending`.
278290
pending_ids: HashSet<PackageId>,
291+
/// The final result of each download. A pair `(token, result)`. This is a
292+
/// temporary holding area, needed because curl can report multiple
293+
/// downloads at once, but the main loop (`wait`) is written to only
294+
/// handle one at a time.
279295
results: Vec<(usize, Result<(), curl::Error>)>,
296+
/// The next ID to use for creating a token (see `Download::token`).
280297
next: usize,
298+
/// Progress bar.
281299
progress: RefCell<Option<Progress<'cfg>>>,
300+
/// Number of downloads that have successfully finished.
282301
downloads_finished: usize,
302+
/// Total bytes for all successfully downloaded packages.
283303
downloaded_bytes: u64,
304+
/// Size (in bytes) and package name of the largest downloaded package.
284305
largest: (u64, String),
306+
/// Time when downloading started.
285307
start: Instant,
308+
/// Indicates *all* downloads were successful.
286309
success: bool,
287310

288311
/// Timeout management, both of timeout thresholds as well as whether or not
@@ -291,10 +314,21 @@ pub struct Downloads<'a, 'cfg: 'a> {
291314
/// Note that timeout management is done manually here instead of in libcurl
292315
/// because we want to apply timeouts to an entire batch of operations, not
293316
/// any one particular single operation.
294-
timeout: ops::HttpTimeout, // timeout configuration
295-
updated_at: Cell<Instant>, // last time we received bytes
296-
next_speed_check: Cell<Instant>, // if threshold isn't 0 by this time, error
297-
next_speed_check_bytes_threshold: Cell<u64>, // decremented when we receive bytes
317+
timeout: ops::HttpTimeout,
318+
/// Last time bytes were received.
319+
updated_at: Cell<Instant>,
320+
/// This is a slow-speed check. It is reset to `now + timeout_duration`
321+
/// every time at least `threshold` bytes are received. If the current
322+
/// time ever exceeds `next_speed_check`, then give up and report a
323+
/// timeout error.
324+
next_speed_check: Cell<Instant>,
325+
/// This is the slow-speed threshold byte count. It starts at the
326+
/// configured threshold value (default 10), and is decremented by the
327+
/// number of bytes received in each chunk. If it is <= zero, the
328+
/// threshold has been met and data is being received fast enough not to
329+
/// trigger a timeout; reset `next_speed_check` and set this back to the
330+
/// configured threshold.
331+
next_speed_check_bytes_threshold: Cell<u64>,
298332
}
299333

300334
struct Download<'cfg> {
@@ -711,6 +745,8 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
711745
Ok(())
712746
}
713747

748+
/// Block, waiting for curl. Returns a token and a `Result` for that token
749+
/// (`Ok` means the download successfully finished).
714750
fn wait_for_curl(&mut self) -> CargoResult<(usize, Result<(), curl::Error>)> {
715751
// This is the main workhorse loop. We use libcurl's portable `wait`
716752
// method to actually perform blocking. This isn't necessarily too

0 commit comments

Comments
 (0)