rotate retransmitting packets

This commit is contained in:
Milo Turner 2020-03-14 15:03:45 -04:00
parent b5b2cd44df
commit 6be8f77a1b
1 changed files with 10 additions and 2 deletions

View File

@ -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<SegIdx> {
self.unacked_segs.iter().map(|(si, _)| *si).next()
fn retrans_seg_idx(&mut self) -> Option<SegIdx> {
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<SegIdx> {
@ -195,6 +202,7 @@ where
}
}
self.unacked_segs = new_unacked_segs;
self.next_retrans_idx = 0;
}
}