From 6be8f77a1b8be214ea2c6e648f5e5ce760408ca4 Mon Sep 17 00:00:00 2001 From: Milo Turner Date: Sat, 14 Mar 2020 15:03:45 -0400 Subject: [PATCH] rotate retransmitting packets --- hptp-send/src/main.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/hptp-send/src/main.rs b/hptp-send/src/main.rs index 9033742..2bd3c55 100644 --- a/hptp-send/src/main.rs +++ b/hptp-send/src/main.rs @@ -77,6 +77,7 @@ struct SegmentSource<'i, IN> { // ordered by seg idx unacked_segs: Vec<(SegIdx, UnAcked)>, next_seg_idx: u32, + next_retrans_idx: usize, // NOTE: this is an index into *unacked_segs* array eof: bool, } @@ -109,6 +110,7 @@ where is_cut: false, unacked_segs: Vec::new(), next_seg_idx: 0, + next_retrans_idx: 0, eof: false, } } @@ -148,8 +150,13 @@ where } } - fn retrans_seg_idx(&self) -> Option { - self.unacked_segs.iter().map(|(si, _)| *si).next() + fn retrans_seg_idx(&mut self) -> Option { + if self.unacked_segs.is_empty() { + return None + } + let seg_idx = self.unacked_segs[self.next_retrans_idx].0; + self.next_retrans_idx = (self.next_retrans_idx + 1) % self.unacked_segs.len(); + Some(seg_idx) } async fn fresh_seg_idx(&mut self) -> Option { @@ -195,6 +202,7 @@ where } } self.unacked_segs = new_unacked_segs; + self.next_retrans_idx = 0; } }