Trait tokio_core::io::FramedIo
[−]
[src]
pub trait FramedIo { type In; type Out; fn poll_read(&mut self) -> Async<()>; fn read(&mut self) -> Poll<Self::Out, Error>; fn poll_write(&mut self) -> Async<()>; fn write(&mut self, req: Self::In) -> Poll<(), Error>; fn flush(&mut self) -> Poll<(), Error>; }
A trait for framed reading and writing.
Most implementations of FramedIo
are for doing protocol level
serialization and deserialization.
Imporantly, the methods of this trait are intended to be used in conjuction with the current task of a future. Namely whenever any of them return a value that indicates "would block" the current future's task is arranged to receive a notification when the method would otherwise not indicate that it would block.
Associated Types
Required Methods
fn poll_read(&mut self) -> Async<()>
Tests to see if this FramedIo
may be readable.
fn read(&mut self) -> Poll<Self::Out, Error>
Read a message frame from the FramedIo
fn poll_write(&mut self) -> Async<()>
Tests to see if this FramedIo
may be writable.
Unlike most other calls to poll readiness, it is important that when
FramedIo::poll_write
returns Async::Ready
that a write will
succeed.
fn write(&mut self, req: Self::In) -> Poll<(), Error>
Write a message frame to the FramedIo
fn flush(&mut self) -> Poll<(), Error>
Flush pending writes or do any other work not driven by reading / writing.
Since the backing source is non-blocking, there is no guarantee that a
call to FramedIo::write
is able to write the full message to the
backing source immediately. In this case, the FramedIo
will need to
buffer the remaining data to write. Calls to FramedIo:flush
attempt
to write any remaining data in the write buffer to the underlying
source.