Skip to content

Commit 03afc05

Browse files
committed
Assign the DatagramBuffer to a variable in places
This makes the code a bit more readable.
1 parent 0eaa4f4 commit 03afc05

File tree

1 file changed

+21
-24
lines changed
  • quinn-proto/src/connection

1 file changed

+21
-24
lines changed

quinn-proto/src/connection/mod.rs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,8 @@ impl Connection {
760760

761761
if close {
762762
trace!("sending CONNECTION_CLOSE");
763+
let mut datagram = transmit.datagram_mut();
764+
763765
// Encode ACKs before the ConnectionClose message, to give the receiver
764766
// a better approximate on what data has been processed. This is
765767
// especially important with ack delay, since the peer might not
@@ -770,7 +772,7 @@ impl Connection {
770772
self.receiving_ecn,
771773
&mut SentFrames::default(),
772774
&mut self.spaces[space_id],
773-
&mut transmit.datagram_mut(),
775+
&mut datagram,
774776
&mut self.stats,
775777
);
776778
}
@@ -779,32 +781,30 @@ impl Connection {
779781
// to encode the ConnectionClose frame too. However we still have the
780782
// check here to prevent crashes if something changes.
781783
debug_assert!(
782-
transmit.datagram().len() + frame::ConnectionClose::SIZE_BOUND
783-
< builder.max_size,
784+
datagram.len() + frame::ConnectionClose::SIZE_BOUND < builder.max_size,
784785
"ACKS should leave space for ConnectionClose"
785786
);
786-
if transmit.datagram().len() + frame::ConnectionClose::SIZE_BOUND < builder.max_size
787-
{
788-
let max_frame_size = builder.max_size - transmit.datagram().len();
787+
if datagram.len() + frame::ConnectionClose::SIZE_BOUND < builder.max_size {
788+
let max_frame_size = builder.max_size - datagram.len();
789789
match self.state {
790790
State::Closed(state::Closed { ref reason }) => {
791791
if space_id == SpaceId::Data || reason.is_transport_layer() {
792-
reason.encode(&mut transmit.datagram_mut(), max_frame_size)
792+
reason.encode(&mut datagram, max_frame_size)
793793
} else {
794794
frame::ConnectionClose {
795795
error_code: TransportErrorCode::APPLICATION_ERROR,
796796
frame_type: None,
797797
reason: Bytes::new(),
798798
}
799-
.encode(&mut transmit.datagram_mut(), max_frame_size)
799+
.encode(&mut datagram, max_frame_size)
800800
}
801801
}
802802
State::Draining => frame::ConnectionClose {
803803
error_code: TransportErrorCode::NO_ERROR,
804804
frame_type: None,
805805
reason: Bytes::new(),
806806
}
807-
.encode(&mut transmit.datagram_mut(), max_frame_size),
807+
.encode(&mut datagram, max_frame_size),
808808
_ => unreachable!(
809809
"tried to make a close packet when the connection wasn't closed"
810810
),
@@ -827,15 +827,14 @@ impl Connection {
827827
// Send an off-path PATH_RESPONSE. Prioritized over on-path data to ensure that path
828828
// validation can occur while the link is saturated.
829829
if space_id == SpaceId::Data && transmit.num_datagrams() == 1 {
830+
let mut datagram = transmit.datagram_mut();
830831
if let Some((token, remote)) = self.path_responses.pop_off_path(self.path.remote) {
831832
// `unwrap` guaranteed to succeed because `builder_storage` was populated just
832833
// above.
833834
let mut builder = builder_storage.take().unwrap();
834835
trace!("PATH_RESPONSE {:08x} (off-path)", token);
835-
transmit
836-
.datagram_mut()
837-
.write(frame::FrameType::PATH_RESPONSE);
838-
transmit.datagram_mut().write(token);
836+
datagram.write(frame::FrameType::PATH_RESPONSE);
837+
datagram.write(token);
839838
self.stats.frame_tx.path_response += 1;
840839
builder.pad_to(MIN_INITIAL_SIZE);
841840
builder.finish_and_track(
@@ -845,7 +844,7 @@ impl Connection {
845844
non_retransmits: true,
846845
..SentFrames::default()
847846
}),
848-
&mut transmit.datagram_mut(),
847+
&mut datagram,
849848
);
850849
self.stats.udp_tx.on_sent(1, transmit.len());
851850
return Some(Transmit {
@@ -859,8 +858,9 @@ impl Connection {
859858
}
860859

861860
let sent = {
862-
let frame_space = builder.max_size - transmit.datagram_mut().len();
863-
let mut buf = transmit.datagram_mut().limit(frame_space);
861+
let datagram = transmit.datagram_mut();
862+
let frame_space = builder.max_size - datagram.len();
863+
let mut buf = datagram.limit(frame_space);
864864
self.populate_packet(now, space_id, &mut buf, builder.exact_number)
865865
};
866866

@@ -916,26 +916,23 @@ impl Connection {
916916

917917
debug_assert_eq!(transmit.num_datagrams(), 0);
918918
transmit.start_new_datagram_with_size(probe_size as usize);
919-
920-
debug_assert!(transmit.datagram().is_empty());
919+
let mut datagram = transmit.datagram_mut();
921920
let mut builder = PacketBuilder::new(
922921
now,
923922
space_id,
924923
self.rem_cids.active(),
925-
&mut transmit.datagram_mut(),
924+
&mut datagram,
926925
true,
927926
self,
928927
)?;
929928

930929
// We implement MTU probes as ping packets padded up to the probe size
931-
transmit.datagram_mut().write(frame::FrameType::PING);
930+
datagram.write(frame::FrameType::PING);
932931
self.stats.frame_tx.ping += 1;
933932

934933
// If supported by the peer, we want no delays to the probe's ACK
935934
if self.peer_supports_ack_frequency() {
936-
transmit
937-
.datagram_mut()
938-
.write(frame::FrameType::IMMEDIATE_ACK);
935+
datagram.write(frame::FrameType::IMMEDIATE_ACK);
939936
self.stats.frame_tx.immediate_ack += 1;
940937
}
941938

@@ -944,7 +941,7 @@ impl Connection {
944941
non_retransmits: true,
945942
..Default::default()
946943
};
947-
builder.finish_and_track(now, self, Some(sent_frames), &mut transmit.datagram_mut());
944+
builder.finish_and_track(now, self, Some(sent_frames), &mut datagram);
948945

949946
self.stats.path.sent_plpmtud_probes += 1;
950947

0 commit comments

Comments
 (0)