Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::io: retry write operation on ErrorKind::WouldBlock #100594

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion library/std/src/io/buffered/bufwriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ impl<W: Write> BufWriter<W> {
));
}
Ok(n) => guard.consume(n),
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {}
Err(ref e)
if e.kind() == io::ErrorKind::Interrupted
|| e.kind() == ErrorKind::WouldBlock => {}
Err(e) => return Err(e),
}
}
Expand Down
34 changes: 20 additions & 14 deletions library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1396,8 +1396,9 @@ pub trait Write {
/// It is **not** considered an error if the entire buffer could not be
/// written to this writer.
///
/// An error of the [`ErrorKind::Interrupted`] kind is non-fatal and the
/// write operation should be retried if there is nothing else to do.
/// An error of kind [`ErrorKind::Interrupted`] or [`ErrorKind::WouldBlock`]
/// is non-fatal and the write operation should be retried if there is
/// nothing else to do.
///
/// # Examples
///
Expand Down Expand Up @@ -1498,18 +1499,19 @@ pub trait Write {
/// Attempts to write an entire buffer into this writer.
///
/// This method will continuously call [`write`] until there is no more data
/// to be written or an error of non-[`ErrorKind::Interrupted`] kind is
/// returned. This method will not return until the entire buffer has been
/// successfully written or such an error occurs. The first error that is
/// not of [`ErrorKind::Interrupted`] kind generated from this method will be
/// returned.
/// to be written or an error is returned that is not of kind [`ErrorKind::Interrupted`]
/// or [`ErrorKind::WouldBlock`]. This method will not return until the
/// entire buffer has been successfully written or such an error occurs. The
/// first error that is not of kind [`ErrorKind::Interrupted`] or
/// [`ErrorKind::WouldBlock`] generated from this method will be returned.
///
/// If the buffer contains no data, this will never call [`write`].
///
/// # Errors
///
/// This function will return the first error of
/// non-[`ErrorKind::Interrupted`] kind that [`write`] returns.
/// that [`write`] returns which is not of kind [`ErrorKind::Interrupted`]
/// or [`ErrorKind::WouldBlock`].
///
/// [`write`]: Write::write
///
Expand Down Expand Up @@ -1537,20 +1539,23 @@ pub trait Write {
));
}
Ok(n) => buf = &buf[n..],
Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
Err(ref e)
if e.kind() == ErrorKind::Interrupted || e.kind() == ErrorKind::WouldBlock => {}
Err(e) => return Err(e),
}
}

Ok(())
}

/// Attempts to write multiple buffers into this writer.
///
/// This method will continuously call [`write_vectored`] until there is no
/// more data to be written or an error of non-[`ErrorKind::Interrupted`]
/// kind is returned. This method will not return until all buffers have
/// been successfully written or such an error occurs. The first error that
/// is not of [`ErrorKind::Interrupted`] kind generated from this method
/// more data to be written or an error is returned that is not of kind
/// [`ErrorKind::Interrupted`] or [`ErrorKind::WouldBlock`]. This method will
/// not return until all buffers have been successfully written or such an
/// error occurs. The first error that is not of kind [`ErrorKind::Interrupted`]
/// or [`ErrorKind::WouldBlock`] generated from this method
/// will be returned.
///
/// If the buffer contains no data, this will never call [`write_vectored`].
Expand Down Expand Up @@ -1605,7 +1610,8 @@ pub trait Write {
));
}
Ok(n) => IoSlice::advance_slices(&mut bufs, n),
Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
Err(ref e)
if e.kind() == ErrorKind::Interrupted || e.kind() == ErrorKind::WouldBlock => {}
Err(e) => return Err(e),
}
}
Expand Down