Trait timeout_io::Reader[][src]

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

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 makes self non-blocking. It's up to you to restore the previous state 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 the amount of bytes read 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: This function makes self non-blocking. It's up to you to restore the previous state 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: This function makes self non-blocking. It's up to you to restore the previous state 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