Skip to content

Commit

Permalink
test(leftpad): use splice
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Volosatovs <[email protected]>
  • Loading branch information
rvolosatovs committed Sep 18, 2024
1 parent cec8cbb commit 6d3cf2e
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions tests/components/wasi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod bindings {

use core::iter::{self, zip};

use wasi_passthrough::bindings::wasi::io::streams::{InputStream, OutputStream, StreamError};
use wasi_passthrough::bindings::wasi::io::streams::{InputStream, OutputStream};

pub struct Handler;

Expand Down Expand Up @@ -56,10 +56,9 @@ impl bindings::exports::west_test::leftpad::leftpad::Guest for Handler {
tx.write(s.as_bytes())?;
}
loop {
match rx.blocking_read(4096) {
Ok(buf) => tx.write(&buf)?,
Err(StreamError::Closed) => return Ok(()),
Err(StreamError::LastOperationFailed(err)) => return Err(wasi_passthrough::bindings::exports::wasi::io::streams::StreamError::LastOperationFailed(err.into()))
let n = tx.splice(&rx, 4096)?;
if n == 0 {
return Ok(());
}
}
}
Expand Down

0 comments on commit 6d3cf2e

Please sign in to comment.