[−][src]Trait timeout_io::Reader
A trait for reading with timeouts
Required methods
fn read(
&mut self,
buffer: &mut [u8],
timeout: Duration
) -> Result<usize, TimeoutIoError>
&mut self,
buffer: &mut [u8],
timeout: Duration
) -> Result<usize, TimeoutIoError>
Executes one read
-operation to read up to buffer.len()
-bytes and returns the amount
of bytes read
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.
fn read_exact(
&mut self,
buffer: &mut [u8],
timeout: Duration
) -> Result<(), TimeoutIoError>
&mut self,
buffer: &mut [u8],
timeout: Duration
) -> Result<(), TimeoutIoError>
Reads until buffer
is 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.
fn read_until(
&mut self,
buffer: &mut [u8],
pattern: &[u8],
timeout: Duration
) -> Result<Option<usize>, TimeoutIoError>
&mut self,
buffer: &mut [u8],
pattern: &[u8],
timeout: Duration
) -> Result<Option<usize>, TimeoutIoError>
Reads until either pattern
is matched or buffer
is filled completely. Returns either
Some(bytes_read)
if the pattern has been matched or None
if buffer
has been filled
completely without matching the pattern.
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.
Implementors
impl<T: Read + WaitForEvent> Reader for T
[src]
impl<T: Read + WaitForEvent> Reader for T
fn read( | [src] |
fn read_exact( | [src] |
fn read_until( | [src] |