Skip to content

Commit 4396f4a

Browse files
committed
Encapsulate access to TransmitBuf::max_datagrams
Also to avoid mutation outside of the transmit_buf module.
1 parent 8125afe commit 4396f4a

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`].
@@ -106,6 +106,12 @@ impl<'a> TransmitBuf<'a> {
106106
self.buf_capacity
107107
}
108108

109+
/// Whether the buffer has capacity for another datagram after the current one
110+
pub(super) fn has_datagram_capacity(&self) -> bool {
111+
let max_buffer_size = self.segment_size * self.max_datagrams;
112+
self.buf_capacity < max_buffer_size
113+
}
114+
109115
/// Clips the datagram size to the current size
110116
///
111117
/// Only valid for the first datagram, when the datagram might be smaller than the

0 commit comments

Comments
 (0)