Trait timeout_io::Reader[][src]

pub trait Reader {
    fn read_oneshot(
        &mut self,
        buffer: &mut SliceQueue<u8>,
        timeout: Duration
    ) -> Result<()>;
fn read_exact(
        &mut self,
        buffer: &mut SliceQueue<u8>,
        timeout: Duration
    ) -> Result<()>;
fn read_until(
        &mut self,
        pattern: &[u8],
        buffer: &mut SliceQueue<u8>,
        timeout: Duration
    ) -> Result<()>; }

A trait for reading with timeouts

Required Methods

Executes one read-operation to read up to buffer.len()-bytes

This is especially useful in packet-based contexts where read-operations are atomic (like in UDP) or if you don't know the amount of bytes in advance

Note: This function catches all interal timeouts/interrupts and returns only if there was either one successful read-operation or the timeout was hit or a non-recoverable error occurred.

Warning: This function allocates buffer.remaining() bytes, so please ensure that you've set an acceptable limit

Warning: self will be switched into nonblocking mode. It's up to you to restore the previous mode if necessary.

Parameters:

  • buffer: The buffer to write the data to
  • timeout: The maximum time this function will wait for self to become readable

Returns either nothing or a corresponding IoError

Reads until buffer has been filled completely

This is especially useful in stream-based contexts where partial-read-calls are common (like in TCP) and you want to read a well-known amount of bytes

Note: This function catches all interal timeouts/interrupts and returns only if either buffer has been filled completely or the timeout was hit or a non-recoverable error occurred.

Warning: The buffer is filled completely, so please ensure that you've set an acceptable limit.

Warning: self will be switched into nonblocking mode. It's up to you to restore the previous mode if necessary.

Parameters:

  • buffer: The buffer to fill with data
  • timeout: The maximum time this function will block

Returns either nothing or a corresponding IoError

Read until either pattern has been matched or buffer has been filled completely

Note: This function catches all interal timeouts/interrupts and returns only if either pattern has been matched or buffer has been filled completely or the timeout was hit or a non-recoverable error occurred.

Warning: The buffer may be filled completely, so please ensure that you've set an acceptable limit

Warning: self will be switched into nonblocking mode. It's up to you to restore the previous mode if necessary.

Parameters:

  • pattern: The pattern up to which you want to read.
  • buffer: The buffer to write the data to
  • timeout: The maximum time this function will block

Returns either

  • Ok(bytes_read) if the pattern was found or
  • Err(IOError(std::io::ErrorKind::NotFound)) if the buffer was filled completely without a match or
  • another corresponding IoError

Implementors