Make fd_write unbuffered; fixes CraneStation/wasmtime#255
This commit is contained in:
@@ -376,15 +376,29 @@ pub(crate) fn fd_write(
|
|||||||
.map(|vec| unsafe { host::iovec_to_host(vec) })
|
.map(|vec| unsafe { host::iovec_to_host(vec) })
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let maybe_host_nwritten = match &mut *fe.fd_object.descriptor {
|
// perform unbuffered writes
|
||||||
Descriptor::File(f) => f.write_vectored(&iovs),
|
let host_nwritten = match &mut *fe.fd_object.descriptor {
|
||||||
|
Descriptor::File(f) => f
|
||||||
|
.write_vectored(&iovs)
|
||||||
|
.map_err(|err| err.raw_os_error().map_or(host::__WASI_EIO, errno_from_host))?,
|
||||||
Descriptor::Stdin => return Err(host::__WASI_EBADF),
|
Descriptor::Stdin => return Err(host::__WASI_EBADF),
|
||||||
Descriptor::Stdout => io::stdout().lock().write_vectored(&iovs),
|
Descriptor::Stdout => {
|
||||||
Descriptor::Stderr => io::stderr().lock().write_vectored(&iovs),
|
// lock for the duration of the scope
|
||||||
};
|
let stdout = io::stdout();
|
||||||
|
let mut stdout = stdout.lock();
|
||||||
let host_nwritten = maybe_host_nwritten
|
let nwritten = stdout
|
||||||
|
.write_vectored(&iovs)
|
||||||
.map_err(|err| err.raw_os_error().map_or(host::__WASI_EIO, errno_from_host))?;
|
.map_err(|err| err.raw_os_error().map_or(host::__WASI_EIO, errno_from_host))?;
|
||||||
|
stdout
|
||||||
|
.flush()
|
||||||
|
.map_err(|err| err.raw_os_error().map_or(host::__WASI_EIO, errno_from_host))?;
|
||||||
|
nwritten
|
||||||
|
}
|
||||||
|
Descriptor::Stderr => io::stderr()
|
||||||
|
.lock()
|
||||||
|
.write_vectored(&iovs)
|
||||||
|
.map_err(|err| err.raw_os_error().map_or(host::__WASI_EIO, errno_from_host))?,
|
||||||
|
};
|
||||||
|
|
||||||
trace!(" | *nwritten={:?}", host_nwritten);
|
trace!(" | *nwritten={:?}", host_nwritten);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user