From c37b767cb93d69d159b1031141bad6a147dbbbfb Mon Sep 17 00:00:00 2001 From: Milo Turner Date: Sat, 14 Mar 2020 15:41:55 -0400 Subject: [PATCH] quit on file completed --- hptp-send/src/main.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/hptp-send/src/main.rs b/hptp-send/src/main.rs index 2bd3c55..8264977 100644 --- a/hptp-send/src/main.rs +++ b/hptp-send/src/main.rs @@ -86,8 +86,6 @@ struct UnAcked { nacks: usize, } -const IN_FLIGHT: usize = 30; - impl UnAcked { fn nack(self) -> Self { Self { @@ -204,6 +202,10 @@ where self.unacked_segs = new_unacked_segs; self.next_retrans_idx = 0; } + + fn is_file_completed(&self) -> bool { + self.eof && self.unacked_segs.is_empty() + } } async fn upload(log: &mut Logger, peer: &mut UpPeer, inp: &mut IN) -> Result<(), Error> @@ -230,7 +232,7 @@ where let mut src = SegmentSource::new(inp); - const DELAY_MS: u64 = (1000 / IN_FLIGHT) as u64; + let in_flight = 66; let mut deadline = Instant::now(); let mut to_send = vec![]; @@ -252,7 +254,8 @@ where let act = match evt { Evt::Timer => { - deadline += Duration::from_millis(DELAY_MS); + let delay_ms = (1000 / in_flight) as u64; + deadline += Duration::from_millis(delay_ms); match src.get_segment().await { Some((seg_idx, payload)) => { log.send_data(seg_idx as usize, payload.len()).await; @@ -267,9 +270,13 @@ where } Evt::Recv(DownMsg::Ack { idxs }) => { - log.debug_msg(format!("got acks: {:?}", idxs)).await; + log.debug_msg(format!("got {} acks", idxs.len())).await; src.ack(&idxs); - Action::Continue + if src.is_file_completed() { + Action::Quit + } else { + Action::Continue + } } };