Browse the docs

silk.platform.wasi.stream.

Owned Preview 2 input and output streams with partial transfers and deadlines.

Details#

Stream owners close their resource on drop. Operations use WASI polling and the supplied monotonic clock. The parent resource, such as a TCP socket or HTTP body, must outlive its streams.

Import as wasi_stream with import silk.platform.wasi.stream as wasi_stream.

Public declarations: 3.

StreamError#

silk
pub enum StreamError

A stream failure: a closed resource, an expired deadline, or another host I/O failure.

Closed#

silk
Closed

Timeout#

silk
Timeout

Host#

silk
Host

InputStream#

silk
pub struct InputStream

An owned Preview 2 input stream. Its parent must outlive it.

OutputStream#

silk
pub struct OutputStream

An owned Preview 2 output stream. Its parent must outlive it.

Implementation InputStream#

silk
impl InputStream

Associated function take#

silk
pub unsafe fn take(handle: u32) -> InputStream

Takes exclusive ownership of a live input-stream handle. The caller keeps its parent alive.

Method handle#

silk
pub fn handle(self: &Self) -> u32

Borrows the handle without transferring ownership. It is valid until this owner is dropped.

Method read#

silk
pub effect fn read(self: &mut Self, output: &mut [u8], deadline: Option<Instant>) -> ReadTransfer
      ! StreamError ? &mut MonotonicClock

Reads a nonempty partial transfer or EOF. An empty output returns zero immediately. An expired deadline fails with Timeout; other failures are Closed or Host.

Implementation Drop for InputStream#

silk
impl Drop for InputStream

Operation drop#

silk
fn drop(self: &mut Self) -> ()

Implementation OutputStream#

silk
impl OutputStream

Associated function take#

silk
pub unsafe fn take(handle: u32) -> OutputStream

Takes exclusive ownership of a live output-stream handle. The caller keeps its parent alive.

Method handle#

silk
pub fn handle(self: &Self) -> u32

Borrows the handle without transferring ownership. It is valid until this owner is dropped.

Method write#

silk
pub effect fn write(self: &mut Self, input: &[u8], deadline: Option<Instant>) -> usize
      ! StreamError ? &mut MonotonicClock

Writes a nonempty partial transfer, honoring host backpressure and the deadline. An empty input returns zero; host I/O errors release their error resource before failing.

Method flush#

silk
pub effect fn flush(self: &mut Self, deadline: Option<Instant>) -> ()
      ! StreamError ? &mut MonotonicClock

Flushes buffered bytes and waits until the host permits another write.

Implementation Drop for OutputStream#

silk
impl Drop for OutputStream

Operation drop#

silk
fn drop(self: &mut Self) -> ()

Category: Native platform.

Profiles: wasm32-wasip2.

View the source of this page