Skip to content

Commit 90fea68

Browse files
committed
Encapsulate access to TransmitBuf::max_datagrams
Also to avoid mutation outside of the transmit_buf module.
1 parent 1eff4e2 commit 90fea68

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

quinn-proto/src/connection/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ impl Connection {
562562
// We need to send 1 more datagram and extend the buffer for that.
563563

564564
// Is 1 more datagram allowed?
565-
if buf.datagram_max_offset() >= buf.segment_size() * buf.max_datagrams {
565+
if !buf.has_datagram_capacity() {
566566
// No more datagrams allowed
567567
break;
568568
}

quinn-proto/src/connection/transmit_buf.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub(super) struct TransmitBuf<'a> {
3737
/// size. All datagrams in between need to be exactly this size.
3838
buf_capacity: usize,
3939
/// The maximum number of datagrams allowed to write into [`TransmitBuf::buf`]
40-
pub(super) max_datagrams: usize,
40+
max_datagrams: usize,
4141
/// The number of datagrams already (partially) written into the buffer
4242
///
4343
/// Incremented by a call to [`TransmitBuf::start_new_datagram`].
@@ -170,6 +170,12 @@ impl<'a> TransmitBuf<'a> {
170170
self.buf_capacity
171171
}
172172

173+
/// Whether the buffer has capacity for another datagram after the current one
174+
pub(super) fn has_datagram_capacity(&self) -> bool {
175+
let max_buffer_size = self.segment_size * self.max_datagrams;
176+
self.buf_capacity < max_buffer_size
177+
}
178+
173179
/// Returns `true` if the buffer did not have anything written into it
174180
pub(super) fn is_empty(&self) -> bool {
175181
self.len() == 0

0 commit comments

Comments
 (0)