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#
pub enum StreamErrorA stream failure: a closed resource, an expired deadline, or another host I/O failure.
Closed#
ClosedTimeout#
TimeoutHost#
HostInputStream#
pub struct InputStreamAn owned Preview 2 input stream. Its parent must outlive it.
OutputStream#
pub struct OutputStreamAn owned Preview 2 output stream. Its parent must outlive it.
Implementation InputStream#
impl InputStreamAssociated function take#
pub unsafe fn take(handle: u32) -> InputStreamTakes exclusive ownership of a live input-stream handle. The caller keeps its parent alive.
Method handle#
pub fn handle(self: &Self) -> u32Borrows the handle without transferring ownership. It is valid until this owner is dropped.
Method read#
pub effect fn read(self: &mut Self, output: &mut [u8], deadline: Option<Instant>) -> ReadTransfer
! StreamError ? &mut MonotonicClockReads 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#
impl Drop for InputStreamOperation drop#
fn drop(self: &mut Self) -> ()Implementation OutputStream#
impl OutputStreamAssociated function take#
pub unsafe fn take(handle: u32) -> OutputStreamTakes exclusive ownership of a live output-stream handle. The caller keeps its parent alive.
Method handle#
pub fn handle(self: &Self) -> u32Borrows the handle without transferring ownership. It is valid until this owner is dropped.
Method write#
pub effect fn write(self: &mut Self, input: &[u8], deadline: Option<Instant>) -> usize
! StreamError ? &mut MonotonicClockWrites 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#
pub effect fn flush(self: &mut Self, deadline: Option<Instant>) -> ()
! StreamError ? &mut MonotonicClockFlushes buffered bytes and waits until the host permits another write.
Implementation Drop for OutputStream#
impl Drop for OutputStreamOperation drop#
fn drop(self: &mut Self) -> ()Category: Native platform.
Profiles: wasm32-wasip2.