Skip to content

Commit

Permalink
⚡️ Read response directly.
Browse files Browse the repository at this point in the history
  • Loading branch information
langyo committed Sep 30, 2024
1 parent 00ee66c commit d211004
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions examples/guest-side/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod html;
mod model;

use anyhow::Result;
use std::io::Read;
use wasi::sockets::{
instance_network::instance_network,
ip_name_lookup::{resolve_addresses, IpAddress},
Expand Down Expand Up @@ -62,7 +63,7 @@ async fn main() -> Result<()> {
break;
}
}
let (input, output) = loop {
let (mut input, output) = loop {
if let Ok(ret) = request.finish_connect() {
break ret;
}
Expand All @@ -75,14 +76,11 @@ async fn main() -> Result<()> {
"{}",
serde_json::to_string(&Msg::new("debug", format!("Sent request"))).unwrap()
);
let response = loop {
// FIXME: Only read 100000 bytes at first
let response = input.read(100000)?;
if response.len() > 0 && response[0] != 0 {
break response;
}
let response = {
let mut ret = "".to_string();
input.read_to_string(&mut ret)?;
ret
};
let response = String::from_utf8_lossy(&response).to_string();
println!(
"{}",
serde_json::to_string(&Msg::new("debug", format!("Response: {:?}", response))).unwrap()
Expand Down

0 comments on commit d211004

Please sign in to comment.