From d6017e5d13bae93e9073c66aac4baaa311b5ff66 Mon Sep 17 00:00:00 2001 From: Jens Reidel Date: Wed, 11 Sep 2024 01:15:34 +0200 Subject: [PATCH] Move the option to Config Signed-off-by: Jens Reidel --- src/proto/stream.rs | 2 +- src/proto/types.rs | 30 ++++++++++++++---------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/proto/stream.rs b/src/proto/stream.rs index 8018812edc1..88fb5fb4693 100644 --- a/src/proto/stream.rs +++ b/src/proto/stream.rs @@ -311,7 +311,7 @@ where fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { // tokio-util calls poll_flush when more than 8096 bytes are pending, otherwise // it returns Ready. We will just replicate that behavior - if self.pending_bytes >= self.inner.decoder().limits.flush_threshold { + if self.pending_bytes >= self.config.flush_threshold { self.as_mut().poll_flush(cx) } else { Poll::Ready(Ok(())) diff --git a/src/proto/types.rs b/src/proto/types.rs index 52a1396dfc3..263424d16c9 100644 --- a/src/proto/types.rs +++ b/src/proto/types.rs @@ -159,7 +159,7 @@ impl TryFrom for CloseCode { /// the backing type is [`Bytes`] with a reference counter greater than one. /// /// [`From`]: #impl-From-for-Payload -/// [`Into`]: #impl-From-for-BytesMut +/// [`Into`]: #impl-From-for-BytesMut pub struct Payload { /// The raw payload data. data: UnsafeCell, @@ -563,9 +563,6 @@ pub struct Limits { /// The maximum allowed payload length. The default /// is 64 MiB. pub(super) max_payload_len: usize, - /// Threshold of queued up bytes after which the underlying I/O is flushed - /// before the sink is declared ready. The default is 8 KiB. - pub(super) flush_threshold: usize, } impl Limits { @@ -574,7 +571,6 @@ impl Limits { pub fn unlimited() -> Self { Self { max_payload_len: usize::MAX, - flush_threshold: usize::MAX, } } @@ -586,23 +582,12 @@ impl Limits { self } - - /// Sets the threshold of queued up bytes after which the underlying I/O is - /// flushed before the sink is declared ready. `None` equals no limit. The - /// default is 8 KiB. - #[must_use] - pub fn flush_threshold(mut self, threshold: Option) -> Self { - self.flush_threshold = threshold.unwrap_or(usize::MAX); - - self - } } impl Default for Limits { fn default() -> Self { Self { max_payload_len: 64 * 1024 * 1024, - flush_threshold: 8 * 1024, } } } @@ -618,6 +603,9 @@ pub struct Config { /// Consider decreasing this if the remote imposes a limit on the frame /// payload size. The default is 4MiB. pub(super) frame_size: usize, + /// Threshold of queued up bytes after which the underlying I/O is flushed + /// before the sink is declared ready. The default is 8 KiB. + pub(super) flush_threshold: usize, } impl Config { @@ -631,12 +619,22 @@ impl Config { self } + + /// Sets the threshold of queued up bytes after which the underlying I/O is + /// flushed before the sink is declared ready. The default is 8 KiB. + #[must_use] + pub fn flush_threshold(mut self, threshold: usize) -> Self { + self.flush_threshold = threshold; + + self + } } impl Default for Config { fn default() -> Self { Self { frame_size: 4 * 1024 * 1024, + flush_threshold: 8 * 1024, } } }