Added --exit-on-download option, only works without the server so far
This commit is contained in:
parent
af30affb37
commit
a800048b7e
4 changed files with 37 additions and 7 deletions
|
|
@ -127,7 +127,7 @@ impl ChunkTracker {
|
|||
}
|
||||
|
||||
pub fn mark_piece_downloaded(&mut self, idx: ValidPieceIndex) {
|
||||
self.have.set(idx.get() as usize, true)
|
||||
self.have.set(idx.get() as usize, true);
|
||||
}
|
||||
|
||||
pub fn is_chunk_downloaded(&self, chunk: &ChunkInfo) -> bool {
|
||||
|
|
|
|||
|
|
@ -140,9 +140,8 @@ impl TorrentManagerHandle {
|
|||
todo!()
|
||||
}
|
||||
pub async fn wait_until_completed(&self) -> anyhow::Result<()> {
|
||||
loop {
|
||||
tokio::time::sleep(Duration::from_secs(60)).await;
|
||||
}
|
||||
self.manager.state.wait_until_completed().await;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ use sha1w::Sha1;
|
|||
use tokio::{
|
||||
sync::{
|
||||
mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender},
|
||||
Semaphore,
|
||||
Notify, Semaphore,
|
||||
},
|
||||
time::timeout,
|
||||
};
|
||||
|
|
@ -242,6 +242,8 @@ pub struct TorrentState {
|
|||
|
||||
peer_semaphore: Semaphore,
|
||||
peer_queue_tx: UnboundedSender<(SocketAddr, UnboundedReceiver<WriterRequest>)>,
|
||||
|
||||
finished_notify: Notify,
|
||||
}
|
||||
|
||||
impl TorrentState {
|
||||
|
|
@ -280,6 +282,7 @@ impl TorrentState {
|
|||
|
||||
peer_semaphore: Semaphore::new(128),
|
||||
peer_queue_tx,
|
||||
finished_notify: Notify::new(),
|
||||
});
|
||||
spawn("peer adder", {
|
||||
let state = state.clone();
|
||||
|
|
@ -582,6 +585,13 @@ impl TorrentState {
|
|||
total_piece_download_ms: self.stats.total_piece_download_ms.load(Relaxed),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn wait_until_completed(&self) {
|
||||
if self.get_left_to_download() == 0 {
|
||||
return;
|
||||
}
|
||||
self.finished_notify.notified().await;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
|
@ -1020,6 +1030,10 @@ impl PeerHandler {
|
|||
index, handle
|
||||
);
|
||||
|
||||
if self.state.get_left_to_download() == 0 {
|
||||
self.state.finished_notify.notify_waiters();
|
||||
}
|
||||
|
||||
self.state.maybe_transmit_haves(chunk_info.piece_index);
|
||||
}
|
||||
false => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue