@@ -263,26 +263,49 @@ impl hash::Hash for Package {
263
263
}
264
264
}
265
265
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.
266
270
pub struct PackageSet < ' cfg > {
267
271
packages : HashMap < PackageId , LazyCell < Package > > ,
268
272
sources : RefCell < SourceMap < ' cfg > > ,
269
273
config : & ' cfg Config ,
270
274
multi : Multi ,
275
+ /// Used to prevent reusing the PackageSet to download twice.
271
276
downloading : Cell < bool > ,
277
+ /// Whether or not to use curl HTTP/2 multiplexing.
272
278
multiplexing : bool ,
273
279
}
274
280
281
+ /// Helper for downloading crates.
275
282
pub struct Downloads < ' a , ' cfg : ' a > {
276
283
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.
277
287
pending : HashMap < usize , ( Download < ' cfg > , EasyHandle ) > ,
288
+ /// Set of packages currently being downloaded. This should stay in sync
289
+ /// with `pending`.
278
290
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.
279
295
results : Vec < ( usize , Result < ( ) , curl:: Error > ) > ,
296
+ /// The next ID to use for creating a token (see `Download::token`).
280
297
next : usize ,
298
+ /// Progress bar.
281
299
progress : RefCell < Option < Progress < ' cfg > > > ,
300
+ /// Number of downloads that have successfully finished.
282
301
downloads_finished : usize ,
302
+ /// Total bytes for all successfully downloaded packages.
283
303
downloaded_bytes : u64 ,
304
+ /// Size (in bytes) and package name of the largest downloaded package.
284
305
largest : ( u64 , String ) ,
306
+ /// Time when downloading started.
285
307
start : Instant ,
308
+ /// Indicates *all* downloads were successful.
286
309
success : bool ,
287
310
288
311
/// Timeout management, both of timeout thresholds as well as whether or not
@@ -291,10 +314,21 @@ pub struct Downloads<'a, 'cfg: 'a> {
291
314
/// Note that timeout management is done manually here instead of in libcurl
292
315
/// because we want to apply timeouts to an entire batch of operations, not
293
316
/// 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 > ,
298
332
}
299
333
300
334
struct Download < ' cfg > {
@@ -711,6 +745,8 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
711
745
Ok ( ( ) )
712
746
}
713
747
748
+ /// Block, waiting for curl. Returns a token and a `Result` for that token
749
+ /// (`Ok` means the download successfully finished).
714
750
fn wait_for_curl ( & mut self ) -> CargoResult < ( usize , Result < ( ) , curl:: Error > ) > {
715
751
// This is the main workhorse loop. We use libcurl's portable `wait`
716
752
// method to actually perform blocking. This isn't necessarily too
0 commit comments