Skip to content

Commit

Permalink
chore: introduce MAX_FRAME_BUFFER
Browse files Browse the repository at this point in the history
  • Loading branch information
jxs committed Feb 26, 2024
1 parent cf6456f commit 6689e22
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions yamux/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ use std::{fmt, sync::Arc, task::Poll};

pub use stream::{Packet, State, Stream};

/// Max queued frames in `Connection`.
const MAX_FRAME_BUFFER: usize = 2000;

/// How the connection is used.
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
pub enum Mode {
Expand Down Expand Up @@ -398,6 +401,11 @@ impl<T: AsyncRead + AsyncWrite + Unpin> Active<T> {
}
}

// Receiver is not reading.
if self.pending_frames.len() == MAX_FRAME_BUFFER {
return Poll::Ready(Err(ConnectionError::Closed));
}

match self.socket.poll_flush_unpin(cx)? {
Poll::Ready(()) => {}
Poll::Pending => {}
Expand Down

0 comments on commit 6689e22

Please sign in to comment.