pub struct IoBuf<S> {
pub in_buf: Buf,
pub out_buf: Buf,
/* private fields */
}
Expand description
A wrapper for full-duplex stream
Fields§
§in_buf: Buf
§out_buf: Buf
Implementations§
Source§impl<S> IoBuf<S>
Main trait of a stream (meaning socket) with input and output buffers
impl<S> IoBuf<S>
Main trait of a stream (meaning socket) with input and output buffers
This is ought to be similar to tokio_core::Io
but with buffers
Sourcepub fn read(&mut self) -> Result<usize, Error>where
S: AsyncRead,
pub fn read(&mut self) -> Result<usize, Error>where
S: AsyncRead,
Read a chunk of data into a buffer
The data just read can then be found in self.in_buf
.
This method does just one read. Because you are ought to try parse request after every read rather than reading a lot of the data in memory.
This method returns 0
when no bytes are read, both when WouldBlock
occurred and when connection has been closed. You may then use
self.done()
to distinguish from these conditions.
Sourcepub fn flush(&mut self) -> Result<(), Error>where
S: AsyncWrite,
pub fn flush(&mut self) -> Result<(), Error>where
S: AsyncWrite,
Write data in the output buffer to actual stream
You should put the data to be sent into self.out_buf
before flush
Sourcepub fn flushed(self) -> Flushed<S>where
S: AsyncWrite,
pub fn flushed(self) -> Flushed<S>where
S: AsyncWrite,
Returns a future which resolves to this stream when output buffer is flushed
Sourcepub fn framed<C: Encode + Decode>(self, codec: C) -> Framed<S, C>
pub fn framed<C: Encode + Decode>(self, codec: C) -> Framed<S, C>
Provides a Stream
and Sink
interface for reading and writing to
this IoBuf
object, using Decode
and Encode
to read and write the
raw data.
Raw I/O objects work with byte sequences, but higher-level code
usually wants to batch these into meaningful chunks, called “frames”.
This method layers framing on top of an I/O object, by using the
Encode
and Decode
traits:
Encode
interprets frames we want to send into bytes;Decode
interprets incoming bytes into a stream of frames.
Note that the incoming and outgoing frame types may be distinct.
This function returns a single object that is both Stream
and
Sink
; grouping this into a single object is often useful for
layering things like gzip or TLS, which require both read and write
access to the underlying object.
If you want to work more directly with the streams and sink, consider
calling split
on the Framed
returned by this method, which will
break them into separate objects, allowing them to interact more
easily.
pub fn split(self) -> (WriteBuf<S>, ReadBuf<S>)where
S: AsyncRead + AsyncWrite,
Trait Implementations§
Source§impl<S: AsyncWrite> Write for IoBuf<S>
impl<S: AsyncWrite> Write for IoBuf<S>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
Source§fn flush(&mut self) -> Result<(), Error>
fn flush(&mut self) -> Result<(), Error>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)