Struct tk_bufstream::IoBuf
[−]
[src]
pub struct IoBuf<S: Io> { pub in_buf: Buf, pub out_buf: Buf, // some fields omitted }
A wrapper for full-duplex stream
Fields
in_buf: Buf
out_buf: Buf
Methods
impl<S: Io> IoBuf<S>
[src]
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
fn new(sock: S) -> IoBuf<S>
Create a new IoBuf object with empty buffers
fn read(&mut self) -> Result<usize, Error>
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.
fn flush(&mut self) -> Result<(), Error>
Write data in the output buffer to actual stream
You should put the data to be sent into self.out_buf
before flush
fn done(&self) -> bool
Returns true when connection is closed by peer
fn flushed(self) -> Flushed<S>
Returns a future which resolves to this stream when output buffer is flushed
fn framed<C: Encode + Decode>(self, codec: C) -> Framed<S, C> where Self: Sized
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.
fn split(self) -> (WriteBuf<S>, ReadBuf<S>)
Trait Implementations
impl<S: Io> Debug for IoBuf<S>
[src]
impl<S: AsRawFd + Io> AsRawFd for IoBuf<S>
[src]
impl<S: Io> Write for IoBuf<S>
[src]
fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
Write a buffer into this object, returning how many bytes were written. Read more
fn flush(&mut self) -> Result<(), Error>
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
1.0.0
Attempts to write an entire buffer into this write. Read more
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
1.0.0
Writes a formatted string into this writer, returning any error encountered. Read more
fn by_ref(&mut self) -> &mut Self
1.0.0
Creates a "by reference" adaptor for this instance of Write
. Read more