@@ -8,16 +8,6 @@ package wasi:io
88interface streams {
99 use wasi :poll /poll . {pollable }
1010
11- /// An error type returned from a stream operation.
12- ///
13- /// TODO: need to figure out the actual contents of this error. Used to be
14- /// an empty record but that's no longer allowed. The `dummy` field is
15- /// only here to have this be a valid in the component model by being
16- /// non-empty.
17- record stream-error {
18- dummy : u32 ,
19- }
20-
2111 /// Streams provide a sequence of data and then end; once they end, they
2212 /// no longer provide any further data.
2313 ///
@@ -37,15 +27,12 @@ interface streams {
3727 /// An input bytestream. In the future, this will be replaced by handle
3828 /// types.
3929 ///
40- /// This conceptually represents a `stream<u8, _>` . It's temporary
41- /// scaffolding until component-model's async features are ready.
42- ///
4330 /// `input-stream` s are *non-blocking* to the extent practical on underlying
4431 /// platforms. I/O operations always return promptly; if fewer bytes are
4532 /// promptly available than requested, they return the number of bytes promptly
4633 /// available, which could even be zero. To wait for data to be available,
4734 /// use the `subscribe-to-input-stream` function to obtain a `pollable` which
48- /// can be polled for using `wasi_poll ` .
35+ /// can be polled for using `wasi:poll/poll.poll_oneoff ` .
4936 ///
5037 /// And at present, it is a `u32` instead of being an actual handle, until
5138 /// the wit-bindgen implementation of handles and resources is ready.
@@ -58,40 +45,36 @@ interface streams {
5845 /// This function returns a list of bytes containing the data that was
5946 /// read, along with a `stream-status` which, indicates whether further
6047 /// reads are expected to produce data. The returned list will contain up to
61- /// `len` bytes; it may return fewer than requested, but not more.
62- ///
63- /// Once a stream has reached the end, subsequent calls to read or
64- /// `skip` will always report end-of-stream rather than producing more
48+ /// `len` bytes; it may return fewer than requested, but not more. An
49+ /// empty list and `stream-status:open` indicates no more data is
50+ /// available at this time, and that the pollable given by
51+ /// `subscribe-to-input-stream` will be ready when more data is available.
52+ ///
53+ /// Once a stream has reached the end, subsequent calls to `read` or
54+ /// `skip` will always report `stream-status:ended` rather than producing more
6555 /// data.
6656 ///
67- /// If `len` is 0, it represents a request to read 0 bytes, which should
68- /// always succeed, assuming the stream hasn't reached its end yet, and
69- /// return an empty list.
70- ///
71- /// The len here is a `u64` , but some callees may not be able to allocate
72- /// a buffer as large as that would imply.
73- /// FIXME: describe what happens if allocation fails.
57+ /// When the caller gives a `len` of 0, it represents a request to read 0
58+ /// bytes. This read should always succeed and return an empty list and
59+ /// the current `stream-status` .
7460 ///
75- /// When the returned `stream-status` is `open` , the length of the returned
76- /// value may be less than `len` . When an empty list is returned, this
77- /// indicates that no more bytes were available from the stream at that
78- /// time. In that case the subscribe-to-input-stream pollable will indicate
79- /// when additional bytes are available for reading.
61+ /// The `len` parameter is a `u64` , which could represent a list of u8 which
62+ /// is not possible to allocate in wasm32, or not desirable to allocate as
63+ /// as a return value by the callee. The callee may return a list of bytes
64+ /// less than `len` in size while more bytes are available for reading.
8065 read : func (
8166 this : input-stream ,
8267 /// The maximum number of bytes to read
8368 len : u64
84- ) -> result <tuple <list <u8 >, stream-status >, stream-error >
69+ ) -> result <tuple <list <u8 >, stream-status >>
8570
86- /// Read bytes from a stream, with blocking.
87- ///
88- /// This is similar to `read` , except that it blocks until at least one
89- /// byte can be read.
71+ /// Read bytes from a stream, after blocking until at least one byte can
72+ /// be read. Except for blocking, identical to `read` .
9073 blocking-read : func (
9174 this : input-stream ,
9275 /// The maximum number of bytes to read
9376 len : u64
94- ) -> result <tuple <list <u8 >, stream-status >, stream-error >
77+ ) -> result <tuple <list <u8 >, stream-status >>
9578
9679 /// Skip bytes from a stream.
9780 ///
@@ -102,40 +85,42 @@ interface streams {
10285 /// `skip` will always report end-of-stream rather than producing more
10386 /// data.
10487 ///
105- /// This function returns the number of bytes skipped, along with a bool
106- /// indicating whether the end of the stream was reached. The returned
107- /// value will be at most `len` ; it may be less.
88+ /// This function returns the number of bytes skipped, along with a
89+ /// `stream-status` indicating whether the end of the stream was
90+ /// reached. The returned value will be at most `len` ; it may be less.
10891 skip : func (
10992 this : input-stream ,
11093 /// The maximum number of bytes to skip.
11194 len : u64 ,
112- ) -> result <tuple <u64 , stream-status >, stream-error >
95+ ) -> result <tuple <u64 , stream-status >>
11396
114- /// Skip bytes from a stream, with blocking.
115- ///
116- /// This is similar to `skip` , except that it blocks until at least one
117- /// byte can be consumed.
97+ /// Skip bytes from a stream, after blocking until at least one byte
98+ /// can be skipped. Except for blocking behavior, identical to `skip` .
11899 blocking-skip : func (
119100 this : input-stream ,
120101 /// The maximum number of bytes to skip.
121102 len : u64 ,
122- ) -> result <tuple <u64 , stream-status >, stream-error >
103+ ) -> result <tuple <u64 , stream-status >>
123104
124105 /// Create a `pollable` which will resolve once either the specified stream
125106 /// has bytes available to read or the other end of the stream has been
126107 /// closed.
108+ /// The created `pollable` is a child resource of the `input-stream` .
109+ /// Implementations may trap if the `input-stream` is dropped before
110+ /// all derived `pollable` s created with this function are dropped.
127111 subscribe-to-input-stream : func (this : input-stream ) -> pollable
128112
129113 /// Dispose of the specified `input-stream` , after which it may no longer
130114 /// be used.
115+ /// Implementations may trap if this `input-stream` is dropped while child
116+ /// `pollable` resources are still alive.
117+ /// After this `input-stream` is dropped, implementations may report any
118+ /// corresponding `output-stream` has `stream-state.closed` .
131119 drop-input-stream : func (this : input-stream )
132120
133121 /// An output bytestream. In the future, this will be replaced by handle
134122 /// types.
135123 ///
136- /// This conceptually represents a `stream<u8, _>` . It's temporary
137- /// scaffolding until component-model's async features are ready.
138- ///
139124 /// `output-stream` s are *non-blocking* to the extent practical on
140125 /// underlying platforms. Except where specified otherwise, I/O operations also
141126 /// always return promptly, after the number of bytes that can be written
@@ -159,45 +144,48 @@ interface streams {
159144 /// When the returned `stream-status` is `open` , the `u64` return value may
160145 /// be less than the length of `buf` . This indicates that no more bytes may
161146 /// be written to the stream promptly. In that case the
162- /// subscribe-to-output-stream pollable will indicate when additional bytes
147+ /// ` subscribe-to-output-stream` pollable will indicate when additional bytes
163148 /// may be promptly written.
164149 ///
165- /// TODO: document what happens when an empty list is written
150+ /// Writing an empty list must return a non-error result with `0` for the
151+ /// `u64` return value, and the current `stream-status` .
166152 write : func (
167153 this : output-stream ,
168154 /// Data to write
169155 buf : list <u8 >
170- ) -> result <tuple <u64 , stream-status >, stream-error >
156+ ) -> result <tuple <u64 , stream-status >>
171157
172- /// Write bytes to a stream, with blocking .
158+ /// Blocking write of bytes to a stream.
173159 ///
174160 /// This is similar to `write` , except that it blocks until at least one
175161 /// byte can be written.
176162 blocking-write : func (
177163 this : output-stream ,
178164 /// Data to write
179165 buf : list <u8 >
180- ) -> result <tuple <u64 , stream-status >, stream-error >
166+ ) -> result <tuple <u64 , stream-status >>
181167
182- /// Write multiple zero bytes to a stream.
168+ /// Write multiple zero- bytes to a stream.
183169 ///
184- /// This function returns a `u64` indicating the number of zero bytes
185- /// that were written; it may be less than `len` .
170+ /// This function returns a `u64` indicating the number of zero-bytes
171+ /// that were written; it may be less than `len` . Equivelant to a call to
172+ /// `write` with a list of zeroes of the given length.
186173 write-zeroes : func (
187174 this : output-stream ,
188- /// The number of zero bytes to write
175+ /// The number of zero- bytes to write
189176 len : u64
190- ) -> result <tuple <u64 , stream-status >, stream-error >
177+ ) -> result <tuple <u64 , stream-status >>
191178
192179 /// Write multiple zero bytes to a stream, with blocking.
193180 ///
194181 /// This is similar to `write-zeroes` , except that it blocks until at least
195- /// one byte can be written.
182+ /// one byte can be written. Equivelant to a call to `blocking-write` with
183+ /// a list of zeroes of the given length.
196184 blocking-write-zeroes : func (
197185 this : output-stream ,
198186 /// The number of zero bytes to write
199187 len : u64
200- ) -> result <tuple <u64 , stream-status >, stream-error >
188+ ) -> result <tuple <u64 , stream-status >>
201189
202190 /// Read from one stream and write to another.
203191 ///
@@ -212,7 +200,7 @@ interface streams {
212200 src : input-stream ,
213201 /// The number of bytes to splice
214202 len : u64 ,
215- ) -> result <tuple <u64 , stream-status >, stream-error >
203+ ) -> result <tuple <u64 , stream-status >>
216204
217205 /// Read from one stream and write to another, with blocking.
218206 ///
@@ -224,7 +212,7 @@ interface streams {
224212 src : input-stream ,
225213 /// The number of bytes to splice
226214 len : u64 ,
227- ) -> result <tuple <u64 , stream-status >, stream-error >
215+ ) -> result <tuple <u64 , stream-status >>
228216
229217 /// Forward the entire contents of an input stream to an output stream.
230218 ///
@@ -242,13 +230,24 @@ interface streams {
242230 this : output-stream ,
243231 /// The stream to read from
244232 src : input-stream
245- ) -> result <tuple <u64 , stream-status >, stream-error >
233+ ) -> result <tuple <u64 , stream-status >>
246234
247235 /// Create a `pollable` which will resolve once either the specified stream
248- /// is ready to accept bytes or the other end of the stream has been closed.
236+ /// is ready to accept bytes or the `stream-state` has become closed.
237+ ///
238+ /// Once the stream-state is closed, this pollable is always ready
239+ /// immediately.
240+ ///
241+ /// The created `pollable` is a child resource of the `output-stream` .
242+ /// Implementations may trap if the `output-stream` is dropped before
243+ /// all derived `pollable` s created with this function are dropped.
249244 subscribe-to-output-stream : func (this : output-stream ) -> pollable
250245
251246 /// Dispose of the specified `output-stream` , after which it may no longer
252247 /// be used.
248+ /// Implementations may trap if this `output-stream` is dropped while
249+ /// child `pollable` resources are still alive.
250+ /// After this `output-stream` is dropped, implementations may report any
251+ /// corresponding `input-stream` has `stream-state.closed` .
253252 drop-output-stream : func (this : output-stream )
254253}
0 commit comments