diff options
author | Jonathan Bastien-Filiatrault <jonathan@zerospam.ca> | 2019-10-31 10:36:24 -0400 |
---|---|---|
committer | Lucio Franco <luciofranco14@gmail.com> | 2019-10-31 10:36:24 -0400 |
commit | 2902e39db0151c9064be535b7983748eb9a0d92f (patch) | |
tree | 9e352da2949594a0071bf4485d3d84152b865570 /tokio-util/src | |
parent | 630d3136dd863b26e7bfbd3e145f63d92f591243 (diff) |
Allow non-destructive access to the read buffer. (#1600)
I need this to implement SMTP pipelining checks. I mostly need to
flush my send buffer when the read buffer is empty before waiting for
the next command.
Diffstat (limited to 'tokio-util/src')
-rw-r--r-- | tokio-util/src/codec/framed.rs | 5 | ||||
-rw-r--r-- | tokio-util/src/codec/framed_read.rs | 9 |
2 files changed, 14 insertions, 0 deletions
diff --git a/tokio-util/src/codec/framed.rs b/tokio-util/src/codec/framed.rs index 8f2317f0..c95d643b 100644 --- a/tokio-util/src/codec/framed.rs +++ b/tokio-util/src/codec/framed.rs @@ -120,6 +120,11 @@ impl<T, U> Framed<T, U> { &mut self.inner.get_mut().get_mut().1 } + /// Returns a reference to the read buffer. + pub fn read_buffer(&self) -> &BytesMut { + self.inner.buffer() + } + /// Consumes the `Frame`, returning its underlying I/O stream. /// /// Note that care should be taken to not tamper with the underlying stream diff --git a/tokio-util/src/codec/framed_read.rs b/tokio-util/src/codec/framed_read.rs index 6f79cb9a..e10f2968 100644 --- a/tokio-util/src/codec/framed_read.rs +++ b/tokio-util/src/codec/framed_read.rs @@ -79,6 +79,11 @@ impl<T, D> FramedRead<T, D> { pub fn decoder_mut(&mut self) -> &mut D { &mut self.inner.inner.1 } + + /// Returns a reference to the read buffer. + pub fn read_buffer(&self) -> &BytesMut { + &self.inner.buffer + } } impl<T, D> Stream for FramedRead<T, D> @@ -174,6 +179,10 @@ impl<T> FramedRead2<T> { pub(crate) fn get_mut(&mut self) -> &mut T { &mut self.inner } + + pub(crate) fn buffer(&self) -> &BytesMut { + &self.buffer + } } impl<T> Stream for FramedRead2<T> |