quit on file completed
This commit is contained in:
parent
7d3715ab02
commit
c37b767cb9
|
@ -86,8 +86,6 @@ struct UnAcked {
|
||||||
nacks: usize,
|
nacks: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
const IN_FLIGHT: usize = 30;
|
|
||||||
|
|
||||||
impl UnAcked {
|
impl UnAcked {
|
||||||
fn nack(self) -> Self {
|
fn nack(self) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -204,6 +202,10 @@ where
|
||||||
self.unacked_segs = new_unacked_segs;
|
self.unacked_segs = new_unacked_segs;
|
||||||
self.next_retrans_idx = 0;
|
self.next_retrans_idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_file_completed(&self) -> bool {
|
||||||
|
self.eof && self.unacked_segs.is_empty()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn upload<IN>(log: &mut Logger, peer: &mut UpPeer, inp: &mut IN) -> Result<(), Error>
|
async fn upload<IN>(log: &mut Logger, peer: &mut UpPeer, inp: &mut IN) -> Result<(), Error>
|
||||||
|
@ -230,7 +232,7 @@ where
|
||||||
|
|
||||||
let mut src = SegmentSource::new(inp);
|
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 deadline = Instant::now();
|
||||||
let mut to_send = vec![];
|
let mut to_send = vec![];
|
||||||
|
|
||||||
|
@ -252,7 +254,8 @@ where
|
||||||
|
|
||||||
let act = match evt {
|
let act = match evt {
|
||||||
Evt::Timer => {
|
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 {
|
match src.get_segment().await {
|
||||||
Some((seg_idx, payload)) => {
|
Some((seg_idx, payload)) => {
|
||||||
log.send_data(seg_idx as usize, payload.len()).await;
|
log.send_data(seg_idx as usize, payload.len()).await;
|
||||||
|
@ -267,9 +270,13 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
Evt::Recv(DownMsg::Ack { idxs }) => {
|
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);
|
src.ack(&idxs);
|
||||||
Action::Continue
|
if src.is_file_completed() {
|
||||||
|
Action::Quit
|
||||||
|
} else {
|
||||||
|
Action::Continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue