summaryrefslogtreecommitdiffstats
path: root/vendor/gix-features/src/interrupt.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
commitc23a457e72abe608715ac76f076f47dc42af07a5 (patch)
tree2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /vendor/gix-features/src/interrupt.rs
parentReleasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz
rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-features/src/interrupt.rs')
-rw-r--r--vendor/gix-features/src/interrupt.rs38
1 files changed, 37 insertions, 1 deletions
diff --git a/vendor/gix-features/src/interrupt.rs b/vendor/gix-features/src/interrupt.rs
index 1f78e613a..dc7a2db17 100644
--- a/vendor/gix-features/src/interrupt.rs
+++ b/vendor/gix-features/src/interrupt.rs
@@ -91,7 +91,7 @@ where
/// A wrapper for implementors of [`std::io::Read`] or [`std::io::BufRead`] with interrupt support.
///
-/// It fails a [read][`std::io::Read::read`] while an interrupt was requested.
+/// It fails a [read][std::io::Read::read] while an interrupt was requested.
pub struct Read<'a, R> {
/// The actual implementor of [`std::io::Read`] to which interrupt support will be added.
pub inner: R,
@@ -123,3 +123,39 @@ where
self.inner.consume(amt)
}
}
+
+/// A wrapper for implementors of [`std::io::Write`] with interrupt checks on each write call.
+///
+/// It fails a [write][std::io::Write::write] while an interrupt was requested.
+pub struct Write<'a, W> {
+ /// The actual implementor of [`std::io::Write`] to which interrupt support will be added.
+ pub inner: W,
+ /// The flag to trigger interruption
+ pub should_interrupt: &'a AtomicBool,
+}
+
+impl<W> io::Write for Write<'_, W>
+where
+ W: std::io::Write,
+{
+ fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
+ if self.should_interrupt.load(Ordering::Relaxed) {
+ return Err(std::io::Error::new(std::io::ErrorKind::Other, "Interrupted"));
+ }
+ self.inner.write(buf)
+ }
+
+ fn flush(&mut self) -> io::Result<()> {
+ // Don't interrupt here, allow flushes to happen to prefer disk consistency.
+ self.inner.flush()
+ }
+}
+
+impl<W> io::Seek for Write<'_, W>
+where
+ W: std::io::Seek,
+{
+ fn seek(&mut self, pos: io::SeekFrom) -> io::Result<u64> {
+ self.inner.seek(pos)
+ }
+}