Browse Source

Implement `write_vectored` for `SandboxedTTYWriter`.

Fixes #629.
pull/825/head
Dan Gohman 5 years ago
committed by Jakub Konka
parent
commit
b8e4354efc
  1. 23
      crates/wasi-common/src/sandboxed_tty_writer.rs

23
crates/wasi-common/src/sandboxed_tty_writer.rs

@ -1,4 +1,4 @@
use std::io::{Result, Write}; use std::io::{IoSlice, Result, Write};
/// An adapter around a `Write` stream that guarantees that its output /// An adapter around a `Write` stream that guarantees that its output
/// is valid UTF-8 and contains no control characters. It does this by /// is valid UTF-8 and contains no control characters. It does this by
@ -124,6 +124,27 @@ where
return Ok(result); return Ok(result);
} }
fn write_vectored(&mut self, bufs: &[IoSlice]) -> Result<usize> {
// Terminal output is [not expected to be atomic], so just write all the
// individual buffers in sequence.
//
// [not expected to be atomic]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html#tag_16_474_08
let mut total_written = 0;
for buf in bufs {
let written = self.write(buf)?;
total_written += written;
// Stop at the first point where the OS writes less than we asked.
if written < buf.len() {
break;
}
}
Ok(total_written)
}
fn flush(&mut self) -> Result<()> { fn flush(&mut self) -> Result<()> {
self.inner.flush() self.inner.flush()
} }

Loading…
Cancel
Save