Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pseudo-streams. (bytecodealliance#29)
* Add pseudo-streams. This add a pseudo-stream type to the wasi-poll interface, and adds ways to obtain streams from command invocation and from files. In the future, it can support sockets too. With this, `command` takes streams for stdin/stdout, rather than filesystem descriptors. Streams support reading and writing, as well as skipping, repeated-element writing, and splicing from one stream to another. And there are `subscribe-*` functions to produce pseudo-futures from pseudo-streams, allowing them to be polled. This makes the polyfill somewhat more complex, but this is largely due to the polyfill being tied to the preview1 API. This replaces the `seek` and `tell` functions, and implemented `fd_seek` and `fd_tell` in terms of the polyfill's own position. Also, add a dedicated stderr API for writing to stderr in a way that tolerates strings that aren't necessarily expected to be newlines. And add a way to test whether stderr is a terminal. * Implement the host side of `poll_oneoff`. This implements pseudo-futures and subscription functions, and adds polling for streams. * Implement clock subscriptions. wasi.wit: - Remove the "timers" API from wasi-clocks, as it's now redundant with pseudo-future clock subscriptions. - Remove `subscribe-wall-clock`. Wall-clock timeouts were implemented by converting them to monotonic-clock timeouts anyway, so just make that explicit in the WASI API, and teach the polyfill how to convert wall-clock timeouts into monotonic-clock timeouts. - Move `subscribe-monotonic-clock` out of wasi-clocks and into wasi-poll, as it's closely tied to the pseudo-futures mechanism and the `poll-oneoff` implementation. - While here, fix `stream-read` and related functions to return an end-of-stream/file indicator. Code changes: - `default_wall_clock()` and `default_monotonic_clock()` now always create a new table entry, rather than holding a table index in the `WasiCtx` which could potentially dangle. - Add support for monotonic-clock poll subscriptions. - Say "wall clock" instead of "system clock" when we have a choice. * Remove the `OFlags::APPEND` flag, which is no longer used.
- Loading branch information