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 + } } };