Skip to content

Commit

Permalink
pushing last touches
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Lee committed Dec 7, 2024
1 parent 1949bbf commit 53a59ee
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
30 changes: 15 additions & 15 deletions src/net/ordered_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,6 @@ impl OrderedBytes {
let mut num_bytes = 0;
let mut writer_ix = 0;

let base = self.smallest_packet_number_index;
let mut base_packet_number = {
if let Some(ref _p) = self.packets[base] {
_p.header.packet_number
} else {
0
}
};

// peek into carry over bytes
if let Some(ref mut c_bytes) = self.carry_over_bytes {
// We can take all of the carry over
Expand All @@ -209,10 +200,19 @@ impl OrderedBytes {
let drained = c_bytes.drain(len..).collect();
buf[writer_ix..writer_ix + len].copy_from_slice(&c_bytes);
self.carry_over_bytes = Some(drained);
return Ok(ConsumeResult::new(0, base_packet_number, len as u64));
return Ok(ConsumeResult::new(0, 0, len as u64));
}
}

let base = self.smallest_packet_number_index;
let base_packet_number = {
if let Some(ref _p) = self.packets[base] {
_p.header.packet_number
} else {
0
}
};

let mut ix = 0;
while ix < MAX_BUFFER_SIZE
&& self.packets[(base + ix) % MAX_BUFFER_SIZE].is_some()
Expand Down Expand Up @@ -246,7 +246,6 @@ impl OrderedBytes {
self.smallest_packet_number_index =
(self.smallest_packet_number_index + 1) % MAX_BUFFER_SIZE;

base_packet_number += 1;
ix += 1;
}

Expand Down Expand Up @@ -305,7 +304,7 @@ mod tests {
// Consumed 100 bytes. This means 1500 - 100 = 1400 bytes are buffered in the left-over
// bytes buffer
let consume = consume_res.unwrap();
assert_eq!(consume.base_packet_number, start_packet_num + 1);
assert_eq!(consume.base_packet_number, start_packet_num);
assert_eq!(consume.num_packets_consumed, 1);
assert_eq!(consume.bytes_consumed, 100);
assert_eq!(payload[..100], buf[..100]);
Expand All @@ -329,7 +328,8 @@ mod tests {

// We now have 1400 - 100 = 1300 bytes left in the carry over.
let consume = consume_res.unwrap();
assert_eq!(consume.base_packet_number, start_packet_num + 1);
// Base packet number should be zero since it's all coming from the carry over
assert_eq!(consume.base_packet_number, 0);
assert_eq!(consume.num_packets_consumed, 0);
assert_eq!(consume.bytes_consumed, 100);
assert_eq!(payload[100..200], buf[..100]);
Expand All @@ -342,7 +342,7 @@ mod tests {
// 1300 of these bytes come from the carry over. The remaining 100 bytes are from the second
// packet we inserted
let consume = consume_res.unwrap();
assert_eq!(consume.base_packet_number, start_packet_num + 2);
assert_eq!(consume.base_packet_number, start_packet_num + 1);
assert_eq!(consume.num_packets_consumed, 1);
assert_eq!(consume.bytes_consumed, 1400);
assert_eq!(payload[200..], buf[..1300]);
Expand Down Expand Up @@ -399,7 +399,7 @@ mod tests {
assert!(consume_res.is_ok());

let consume = consume_res.unwrap();
assert_eq!(consume.base_packet_number, start_packet_num + 1);
assert_eq!(consume.base_packet_number, start_packet_num);
assert_eq!(consume.num_packets_consumed, 1);
assert_eq!(consume.bytes_consumed, 1);
assert_eq!(buf, [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
Expand Down
2 changes: 1 addition & 1 deletion src/worker/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl ReaderRxChannel {
let base_packet_num = consume_res.get_base_packet_number();

// We need to send an ack.
if num_packets_consumed > 0 {
if num_packets_consumed > 0 && base_packet_num != 0 {
if let Err(e) = self
.writer_tx_channel
.send_ack(base_packet_num, num_packets_consumed)
Expand Down
2 changes: 1 addition & 1 deletion src/worker/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl WriterTxChannel {
}

self.num_runs_without_sleep += 1;
if self.num_runs_without_sleep >= 137 {
if self.num_runs_without_sleep >= 100 {
sleep(Duration::from_nanos(10)).await;
self.num_runs_without_sleep = 0;
}
Expand Down

0 comments on commit 53a59ee

Please sign in to comment.