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
fn read_oneshot(
&mut self,
buffer: &mut SliceQueue<u8>,
timeout: Duration
) -> Result<()>
&mut self,
buffer: &mut SliceQueue<u8>,
timeout: Duration
) -> Result<()>
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: 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 totimeout
: The maximum time this function will wait forself
to become readable
Returns either nothing or a corresponding IoError
fn read_exact(
&mut self,
buffer: &mut SliceQueue<u8>,
timeout: Duration
) -> Result<()>
&mut self,
buffer: &mut SliceQueue<u8>,
timeout: Duration
) -> Result<()>
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: 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 datatimeout
: The maximum time this function will block
Returns either nothing or a corresponding IoError
fn read_until(
&mut self,
pattern: &[u8],
buffer: &mut SliceQueue<u8>,
timeout: Duration
) -> Result<()>
&mut self,
pattern: &[u8],
buffer: &mut SliceQueue<u8>,
timeout: Duration
) -> Result<()>
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: 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 totimeout
: The maximum time this function will block
Returns either
Ok(bytes_read)
if the pattern was found orErr(IOError(std::io::ErrorKind::NotFound))
if the buffer was filled completely without a match or- another corresponding
IoError
Implementors
impl<T: Read + WaitForEvent> Reader for T