Skip to content

Commit 6ded916

Browse files
committed
Add an build method to the TransmitBuilder
1 parent 0f261f6 commit 6ded916

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

quinn-proto/src/connection/mod.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -964,20 +964,12 @@ impl Connection {
964964
.udp_tx
965965
.on_sent(transmit.num_datagrams() as u64, transmit.len());
966966

967-
Some(Transmit {
968-
destination: self.path.remote,
969-
size: transmit.len(),
970-
ecn: if self.path.sending_ecn {
971-
Some(EcnCodepoint::Ect0)
972-
} else {
973-
None
974-
},
975-
segment_size: match transmit.num_datagrams() {
976-
1 => None,
977-
_ => Some(transmit.segment_size()),
978-
},
979-
src_ip: self.local_ip,
980-
})
967+
let ecn = if self.path.sending_ecn {
968+
Some(EcnCodepoint::Ect0)
969+
} else {
970+
None
971+
};
972+
Some(transmit.build(self.path.remote, ecn, self.local_ip))
981973
}
982974

983975
/// Send PATH_CHALLENGE for a previous path if necessary

quinn-proto/src/connection/transmit_builder.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
use std::net::{IpAddr, SocketAddr};
12
use std::ops::{Deref, DerefMut};
23

34
use bytes::BufMut;
45

6+
use crate::{EcnCodepoint, Transmit};
7+
58
/// The buffer in which to write datagrams for [`Connection::poll_transmit`]
69
///
710
/// The `poll_transmit` function writes zero or more datagrams to a buffer. Multiple
@@ -155,6 +158,24 @@ impl<'a> TransmitBuilder<'a> {
155158
)
156159
}
157160

161+
pub(super) fn build(
162+
self,
163+
destination: SocketAddr,
164+
ecn: Option<EcnCodepoint>,
165+
src_ip: Option<IpAddr>,
166+
) -> Transmit {
167+
Transmit {
168+
destination,
169+
ecn,
170+
size: self.len(),
171+
segment_size: match self.num_datagrams {
172+
1 => None,
173+
_ => Some(self.segment_size),
174+
},
175+
src_ip,
176+
}
177+
}
178+
158179
/// Returns the bytes written into the current datagram
159180
pub(super) fn datagram(&self) -> &[u8] {
160181
&self.buf[self.datagram_start..]

0 commit comments

Comments
 (0)