mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-30 21:04:35 +01:00
allow to check if Framed's write buffer is full
This commit is contained in:
parent
f13a0925f7
commit
9a3321b153
@ -85,7 +85,12 @@ impl<T, U> Framed<T, U> {
|
|||||||
pub fn from_parts(parts: FramedParts<T, U>) -> Framed<T, U> {
|
pub fn from_parts(parts: FramedParts<T, U>) -> Framed<T, U> {
|
||||||
Framed {
|
Framed {
|
||||||
inner: framed_read2_with_buffer(
|
inner: framed_read2_with_buffer(
|
||||||
framed_write2_with_buffer(Fuse(parts.io, parts.codec), parts.write_buf, parts.write_buf_lw, parts.write_buf_hw),
|
framed_write2_with_buffer(
|
||||||
|
Fuse(parts.io, parts.codec),
|
||||||
|
parts.write_buf,
|
||||||
|
parts.write_buf_lw,
|
||||||
|
parts.write_buf_hw,
|
||||||
|
),
|
||||||
parts.read_buf,
|
parts.read_buf,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
@ -121,6 +126,11 @@ impl<T, U> Framed<T, U> {
|
|||||||
&mut self.inner.get_mut().get_mut().0
|
&mut self.inner.get_mut().get_mut().0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check if write buffer is full.
|
||||||
|
pub fn is_full(&self) -> bool {
|
||||||
|
self.inner.get_ref().is_full()
|
||||||
|
}
|
||||||
|
|
||||||
/// Consumes the `Frame`, returning its underlying I/O stream.
|
/// Consumes the `Frame`, returning its underlying I/O stream.
|
||||||
///
|
///
|
||||||
/// Note that care should be taken to not tamper with the underlying stream
|
/// Note that care should be taken to not tamper with the underlying stream
|
||||||
|
@ -72,6 +72,11 @@ impl<T, E> FramedWrite<T, E> {
|
|||||||
pub fn encoder_mut(&mut self) -> &mut E {
|
pub fn encoder_mut(&mut self) -> &mut E {
|
||||||
&mut self.inner.inner.1
|
&mut self.inner.inner.1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check if write buffer is full
|
||||||
|
pub fn is_full(&self) -> bool {
|
||||||
|
self.inner.is_full()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, E> Sink for FramedWrite<T, E>
|
impl<T, E> Sink for FramedWrite<T, E>
|
||||||
@ -123,7 +128,11 @@ where
|
|||||||
|
|
||||||
// ===== impl FramedWrite2 =====
|
// ===== impl FramedWrite2 =====
|
||||||
|
|
||||||
pub fn framed_write2<T>(inner: T, low_watermark: usize, high_watermark: usize) -> FramedWrite2<T> {
|
pub fn framed_write2<T>(
|
||||||
|
inner: T,
|
||||||
|
low_watermark: usize,
|
||||||
|
high_watermark: usize,
|
||||||
|
) -> FramedWrite2<T> {
|
||||||
FramedWrite2 {
|
FramedWrite2 {
|
||||||
inner,
|
inner,
|
||||||
low_watermark,
|
low_watermark,
|
||||||
@ -132,7 +141,12 @@ pub fn framed_write2<T>(inner: T, low_watermark: usize, high_watermark: usize) -
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn framed_write2_with_buffer<T>(inner: T, mut buffer: BytesMut, low_watermark: usize, high_watermark: usize) -> FramedWrite2<T> {
|
pub fn framed_write2_with_buffer<T>(
|
||||||
|
inner: T,
|
||||||
|
mut buffer: BytesMut,
|
||||||
|
low_watermark: usize,
|
||||||
|
high_watermark: usize,
|
||||||
|
) -> FramedWrite2<T> {
|
||||||
if buffer.capacity() < high_watermark {
|
if buffer.capacity() < high_watermark {
|
||||||
let bytes_to_reserve = high_watermark - buffer.capacity();
|
let bytes_to_reserve = high_watermark - buffer.capacity();
|
||||||
buffer.reserve(bytes_to_reserve);
|
buffer.reserve(bytes_to_reserve);
|
||||||
@ -155,12 +169,21 @@ impl<T> FramedWrite2<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_parts(self) -> (T, BytesMut, usize, usize) {
|
pub fn into_parts(self) -> (T, BytesMut, usize, usize) {
|
||||||
(self.inner, self.buffer, self.low_watermark, self.high_watermark)
|
(
|
||||||
|
self.inner,
|
||||||
|
self.buffer,
|
||||||
|
self.low_watermark,
|
||||||
|
self.high_watermark,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_mut(&mut self) -> &mut T {
|
pub fn get_mut(&mut self) -> &mut T {
|
||||||
&mut self.inner
|
&mut self.inner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_full(&self) -> bool {
|
||||||
|
self.buffer.len() >= self.high_watermark
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Sink for FramedWrite2<T>
|
impl<T> Sink for FramedWrite2<T>
|
||||||
|
Loading…
Reference in New Issue
Block a user