Trait Io

Source
pub trait Io: Read + Write {
    // Provided methods
    fn poll_read(&mut self) -> Async<()> { ... }
    fn poll_write(&mut self) -> Async<()> { ... }
    fn read_vec(&mut self, bufs: &mut [&mut IoVec]) -> Result<usize, Error> { ... }
    fn write_vec(&mut self, bufs: &[&IoVec]) -> Result<usize, Error> { ... }
    fn framed<C>(self, codec: C) -> Framed<Self, C>
       where C: Codec,
             Self: Sized { ... }
    fn split(self) -> (ReadHalf<Self>, WriteHalf<Self>)
       where Self: Sized { ... }
}
👎Deprecated: moved to the tokio-io crate
Expand description

A trait for read/write I/O objects

This trait represents I/O objects which are readable and writable. Additionally, they’re associated with the ability to test whether they’re readable or writable.

Importantly, the methods of this trait are intended to be used in conjunction 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.

Provided Methods§

Source

fn poll_read(&mut self) -> Async<()>

👎Deprecated: moved to the tokio-io crate

Tests to see if this I/O object may be readable.

This method returns an Async<()> indicating whether the object might be readable. It is possible that even if this method returns Async::Ready that a call to read would return a WouldBlock error.

There is a default implementation for this function which always indicates that an I/O object is readable, but objects which can implement a finer grained version of this are recommended to do so.

If this function returns Async::NotReady then the current future’s task is arranged to receive a notification when it might not return NotReady.

§Panics

This method is likely to panic if called from outside the context of a future’s task.

Source

fn poll_write(&mut self) -> Async<()>

👎Deprecated: moved to the tokio-io crate

Tests to see if this I/O object may be writable.

This method returns an Async<()> indicating whether the object might be writable. It is possible that even if this method returns Async::Ready that a call to write would return a WouldBlock error.

There is a default implementation for this function which always indicates that an I/O object is writable, but objects which can implement a finer grained version of this are recommended to do so.

If this function returns Async::NotReady then the current future’s task is arranged to receive a notification when it might not return NotReady.

§Panics

This method is likely to panic if called from outside the context of a future’s task.

Source

fn read_vec(&mut self, bufs: &mut [&mut IoVec]) -> Result<usize, Error>

👎Deprecated: moved to the tokio-io crate

Read in a list of buffers all at once.

This operation will attempt to read bytes from this socket and place them into the list of buffers provided. Note that each buffer is an IoVec which can be created from a byte slice.

The buffers provided will be filled in sequentially. A buffer will be entirely filled up before the next is written to.

The number of bytes read is returned, if successful, or an error is returned otherwise. If no bytes are available to be read yet then a “would block” error is returned. This operation should not block.

There is a default implementation for this function which treats this as a single read using the first buffer in the list, but objects which can implement this as an atomic read using all the buffers are recommended to do so. For example, TcpStream can implement this using the readv syscall.

Source

fn write_vec(&mut self, bufs: &[&IoVec]) -> Result<usize, Error>

👎Deprecated: moved to the tokio-io crate

Write a list of buffers all at once.

This operation will attempt to write a list of byte buffers to this socket. Note that each buffer is an IoVec which can be created from a byte slice.

The buffers provided will be written sequentially. A buffer will be entirely written before the next is written.

The number of bytes written is returned, if successful, or an error is returned otherwise. If the socket is not currently writable then a “would block” error is returned. This operation should not block.

There is a default implementation for this function which writes the first buffer only, but objects which can implement this as an atomic write using all the buffers are recommended to do so. For example, TcpStream can implement this using the writev syscall.

Source

fn framed<C>(self, codec: C) -> Framed<Self, C>
where C: Codec, Self: Sized,

👎Deprecated: moved to the tokio-io crate

Provides a Stream and Sink interface for reading and writing to this Io 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 Codec traits to handle encoding and decoding of messages 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.

Source

fn split(self) -> (ReadHalf<Self>, WriteHalf<Self>)
where Self: Sized,

👎Deprecated: moved to the tokio-io crate

Helper method for splitting this read/write object into two halves.

The two halves returned implement the Read and Write traits, respectively.

Implementors§

Source§

impl Io for TcpStream

Source§

impl<'a> Io for &'a TcpStream

Source§

impl<'a, E> Io for &'a PollEvented<E>
where &'a E: Read + Write,

Source§

impl<E> Io for PollEvented<E>
where E: Read + Write,