[−][src]Trait timeout_io::Reader
A trait for reading with timeouts
Required methods
fn try_read(
&mut self,
buf: &mut [u8],
pos: &mut usize,
timeout: Duration
) -> Result<(), TimeoutIoError>
&mut self,
buf: &mut [u8],
pos: &mut usize,
timeout: Duration
) -> Result<(), TimeoutIoError>
Executes one read
-operation to read as much bytes as possible into buf[*pos..]
and
adjusts pos
accordingly
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 internal 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: self
must non-blocking or the function won't work as expected
fn try_read_exact(
&mut self,
buf: &mut [u8],
pos: &mut usize,
timeout: Duration
) -> Result<(), TimeoutIoError>
&mut self,
buf: &mut [u8],
pos: &mut usize,
timeout: Duration
) -> Result<(), TimeoutIoError>
Reads until buf[*pos..]
is filled completely and adjusts pos
on every successful
read
-call (so that you can continue seamlessly on TimedOut
-errors etc.)
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 internal timeouts/interrupts and returns only if either
buf
has been filled completely or the timeout
was exceeded or a non-recoverable error
occurred.
Warning: self
must non-blocking or the function won't work as expected
fn try_read_until(
&mut self,
buf: &mut [u8],
pos: &mut usize,
pat: &[u8],
timeout: Duration
) -> Result<bool, TimeoutIoError>
&mut self,
buf: &mut [u8],
pos: &mut usize,
pat: &[u8],
timeout: Duration
) -> Result<bool, TimeoutIoError>
Reads until either pat
is matched or buf
is filled completely and adjusts pos
accordingly. Returns true
if pat
was matched and false
otherwise.
Note: While the reading is continued at *pos
, pat
is matched against the entire buf
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: self
must non-blocking or the function won't work as expected
Implementors
impl<T: Read + WaitForEvent> Reader for T
[src]
fn try_read(
&mut self,
buf: &mut [u8],
pos: &mut usize,
timeout: Duration
) -> Result<(), TimeoutIoError>
[src]
&mut self,
buf: &mut [u8],
pos: &mut usize,
timeout: Duration
) -> Result<(), TimeoutIoError>
fn try_read_exact(
&mut self,
buf: &mut [u8],
pos: &mut usize,
timeout: Duration
) -> Result<(), TimeoutIoError>
[src]
&mut self,
buf: &mut [u8],
pos: &mut usize,
timeout: Duration
) -> Result<(), TimeoutIoError>
fn try_read_until(
&mut self,
buf: &mut [u8],
pos: &mut usize,
pat: &[u8],
timeout: Duration
) -> Result<bool, TimeoutIoError>
[src]
&mut self,
buf: &mut [u8],
pos: &mut usize,
pat: &[u8],
timeout: Duration
) -> Result<bool, TimeoutIoError>