Skip to content

Commit c49d090

Browse files
committed
Specify behavior of write_all for ErrorKind::Interrupted errors
Also spell out that read and write operations should be retried on `ErrorKind::Interrupted` errors. Fixes #38494.
1 parent 535ee6c commit c49d090

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/libstd/io/mod.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,9 @@ pub trait Read {
466466
/// variant will be returned. If an error is returned then it must be
467467
/// guaranteed that no bytes were read.
468468
///
469+
/// An error of the `ErrorKind::Interrupted` kind is non-fatal and the read
470+
/// operation should be retried if there is nothing else to do.
471+
///
469472
/// # Examples
470473
///
471474
/// [`File`][file]s implement `Read`:
@@ -481,7 +484,7 @@ pub trait Read {
481484
/// let mut f = File::open("foo.txt")?;
482485
/// let mut buffer = [0; 10];
483486
///
484-
/// // read 10 bytes
487+
/// // read up to 10 bytes
485488
/// f.read(&mut buffer[..])?;
486489
/// # Ok(())
487490
/// # }
@@ -885,6 +888,9 @@ pub trait Write {
885888
/// It is **not** considered an error if the entire buffer could not be
886889
/// written to this writer.
887890
///
891+
/// An error of the `ErrorKind::Interrupted` kind is non-fatal and the
892+
/// write operation should be retried if there is nothing else to do.
893+
///
888894
/// # Examples
889895
///
890896
/// ```
@@ -894,6 +900,7 @@ pub trait Write {
894900
/// # fn foo() -> std::io::Result<()> {
895901
/// let mut buffer = File::create("foo.txt")?;
896902
///
903+
/// // Writes some prefix of the byte string, not necessarily all of it.
897904
/// buffer.write(b"some bytes")?;
898905
/// # Ok(())
899906
/// # }
@@ -929,14 +936,17 @@ pub trait Write {
929936

930937
/// Attempts to write an entire buffer into this write.
931938
///
932-
/// This method will continuously call `write` while there is more data to
933-
/// write. This method will not return until the entire buffer has been
934-
/// successfully written or an error occurs. The first error generated from
935-
/// this method will be returned.
939+
/// This method will continuously call `write` until there is no more data
940+
/// to be written or an error of non-`ErrorKind::Interrupted` kind is
941+
/// returned. This method will not return until the entire buffer has been
942+
/// successfully written or such an error occurs. The first error that is
943+
/// not of `ErrorKind::Interrupted` kind generated from this method will be
944+
/// returned.
936945
///
937946
/// # Errors
938947
///
939-
/// This function will return the first error that `write` returns.
948+
/// This function will return the first error of
949+
/// non-`ErrorKind::Interrupted` kind that `write` returns.
940950
///
941951
/// # Examples
942952
///

0 commit comments

Comments
 (0)