Skip to content

Commit fbe2644

Browse files
committed
Remove use of absolute offsets
This completely removes the need for TransmitBuilder::datagram_start_offset and ::datagram_max_offset, now that everything can work with the buffer returned by TransmitBuilder::datagram_mut(). It also removes a now unused field in the packet builder since it no longer needs to keep track of the start offset of the datagram: it is always 0 now.
1 parent eb78257 commit fbe2644

File tree

3 files changed

+7
-26
lines changed

3 files changed

+7
-26
lines changed

quinn-proto/src/connection/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,7 @@ impl Connection {
648648
- builder.partial_encode.start
649649
+ builder.tag_len;
650650
if packet_len_unpadded + MAX_PADDING < transmits.segment_size()
651-
|| transmits.datagram_start_offset() + transmits.segment_size()
652-
> transmits.datagram_max_offset()
651+
|| transmits.datagram_mut().capacity() < transmits.segment_size()
653652
{
654653
trace!(
655654
"GSO truncated by demand for {} padding bytes or loss probe",
@@ -713,7 +712,7 @@ impl Connection {
713712
}
714713
}
715714

716-
debug_assert!(transmits.datagram_max_offset() - transmits.len() >= MIN_PACKET_SPACE);
715+
debug_assert!(transmits.datagram_mut().remaining_mut() >= MIN_PACKET_SPACE);
717716

718717
//
719718
// From here on, we've determined that a packet will definitely be sent.
@@ -869,8 +868,7 @@ impl Connection {
869868
!(sent.is_ack_only(&self.streams)
870869
&& !can_send.acks
871870
&& can_send.other
872-
&& (transmits.datagram_max_offset() - builder.datagram_start)
873-
== self.path.current_mtu() as usize
871+
&& transmits.datagram_mut().capacity() == self.path.current_mtu() as usize
874872
&& self.datagrams.outgoing.is_empty()),
875873
"SendableFrames was {can_send:?}, but only ACKs have been written"
876874
);
@@ -913,7 +911,7 @@ impl Connection {
913911
debug_assert_eq!(transmits.num_datagrams(), 0);
914912
transmits.start_new_datagram_with_size(probe_size as usize);
915913

916-
debug_assert_eq!(transmits.datagram_start_offset(), 0);
914+
debug_assert!(transmits.datagram().is_empty());
917915
let mut builder = PacketBuilder::new(
918916
now,
919917
space_id,
@@ -1005,7 +1003,7 @@ impl Connection {
10051003
// sent once, immediately after migration, when the CID is known to be valid. Even
10061004
// if a post-migration packet caused the CID to be retired, it's fair to pretend
10071005
// this is sent first.
1008-
debug_assert_eq!(transmits.datagram_start_offset(), 0);
1006+
debug_assert!(transmits.datagram().is_empty());
10091007
let mut builder =
10101008
PacketBuilder::new(now, SpaceId::Data, *prev_cid, transmits, false, self)?;
10111009
trace!("validating previous path with PATH_CHALLENGE {:08x}", token);

quinn-proto/src/connection/packet_builder.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use crate::{
1111
};
1212

1313
pub(super) struct PacketBuilder {
14-
pub(super) datagram_start: usize,
1514
pub(super) space: SpaceId,
1615
pub(super) partial_encode: PartialEncode,
1716
pub(super) ack_eliciting: bool,
@@ -154,7 +153,6 @@ impl PacketBuilder {
154153
debug_assert!(max_size >= min_size);
155154

156155
Some(Self {
157-
datagram_start: transmits.datagram_start_offset(),
158156
space: space_id,
159157
partial_encode,
160158
exact_number,

quinn-proto/src/connection/transmit_builder.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -185,27 +185,12 @@ impl<'a> TransmitBuilder<'a> {
185185
self.max_datagrams
186186
}
187187

188-
/// Returns the start offset of the current datagram in the buffer
189-
///
190-
/// In other words, this offset contains the first byte of the current datagram.
191-
pub(super) fn datagram_start_offset(&self) -> usize {
192-
self.datagram_start
193-
}
194-
195-
/// Returns the maximum offset in the buffer allowed for the current datagram
196-
///
197-
/// The first and last datagram in a batch are allowed to be smaller then the maximum
198-
/// size. All datagrams in between need to be exactly this size.
199-
pub(super) fn datagram_max_offset(&self) -> usize {
200-
self.buf_capacity
201-
}
202-
203-
/// Returns `true` if the buffer did not have anything written into it
188+
/// Returns `true` if there are no datagrams in this transmit
204189
pub(super) fn is_empty(&self) -> bool {
205190
self.len() == 0
206191
}
207192

208-
/// The number of bytes written into the buffer so far
193+
/// Returns the sum of the bytes for all datagrams in the builder
209194
pub(super) fn len(&self) -> usize {
210195
self.buf.len()
211196
}

0 commit comments

Comments
 (0)