Skip to content

Commit 926646f

Browse files
authored
Rollup merge of rust-lang#85288 - Geal:clarify-std-io-read, r=dtolnay
add an example to explain std::io::Read::read returning 0 in some cases I have always found the explanation about `Read::read` returning 0 to indicate EOF but not indefinitely, so here's more info using Linux as example. I can also add example code if necessary
2 parents 2fa427f + 61bbd6e commit 926646f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

std/src/io/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,12 @@ pub trait Read {
526526
///
527527
/// 1. This reader has reached its "end of file" and will likely no longer
528528
/// be able to produce bytes. Note that this does not mean that the
529-
/// reader will *always* no longer be able to produce bytes.
529+
/// reader will *always* no longer be able to produce bytes. As an example,
530+
/// on Linux, this method will call the `recv` syscall for a [`TcpStream`],
531+
/// where returning zero indicates the connection was shut down correctly. While
532+
/// for [`File`], it is possible to reach the end of file and get zero as result,
533+
/// but if more data is appended to the file, future calls to `read` will return
534+
/// more data.
530535
/// 2. The buffer specified was 0 bytes in length.
531536
///
532537
/// It is not an error if the returned value `n` is smaller than the buffer size,
@@ -568,6 +573,7 @@ pub trait Read {
568573
///
569574
/// [`Ok(n)`]: Ok
570575
/// [`File`]: crate::fs::File
576+
/// [`TcpStream`]: crate::net::TcpStream
571577
///
572578
/// ```no_run
573579
/// use std::io;

0 commit comments

Comments
 (0)