Skip to content

Commit f3558ac

Browse files
committed
Add identical changes to the async Read variant
1 parent 92dbaf2 commit f3558ac

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

embedded-io-async/src/lib.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,23 @@ pub use embedded_io::{
1919
pub trait Read: ErrorType {
2020
/// Read some bytes from this source into the specified buffer, returning how many bytes were read.
2121
///
22-
/// If no bytes are currently available to read, this function waits until at least one byte is available.
23-
///
24-
/// If bytes are available, a non-zero amount of bytes is read to the beginning of `buf`, and the amount
25-
/// is returned. It is not guaranteed that *all* available bytes are returned, it is possible for the
26-
/// implementation to read an amount of bytes less than `buf.len()` while there are more bytes immediately
27-
/// available.
22+
/// If no bytes are currently available to read:
23+
/// - The method waits until at least one byte becomes available;
24+
/// - Once at least one (or more) bytes become available, a non-zero amount of those is copied to the
25+
/// beginning of `buf`, and the amount is returned, *without waiting any further for more bytes to
26+
/// become available*.
27+
///
28+
/// If bytes are available to read:
29+
/// - A non-zero amount of bytes is read to the beginning of `buf`, and the amount is returned immediately,
30+
/// *without waiting for more bytes to become available*;
31+
/// - It is not guaranteed that *all* available bytes are returned, it is possible for the implementation to
32+
/// read an amount of bytes less than `buf.len()` while there are more bytes immediately available.
33+
///
34+
/// This waiting behavior is important for the cases where `Read` represents the "read" leg of a pipe-like
35+
/// protocol (a socket, a pipe, a serial line etc.). The semantics is that the caller - by passing a non-empty
36+
/// buffer - does expect _some_ data (one or more bytes) - but _not necessarily `buf.len()` or more bytes_ -
37+
/// to become available, before the peer represented by `Read` would stop sending bytes due to
38+
/// application-specific reasons (as in the peer waiting for a response to the data it had sent so far).
2839
///
2940
/// If the reader is at end-of-file (EOF), `Ok(0)` is returned. There is no guarantee that a reader at EOF
3041
/// will always be so in the future, for example a reader can stop being at EOF if another process appends

0 commit comments

Comments
 (0)