Sockets: running actors get TCP, UDP, and DNS through wasi:sockets; candidates get no network

This commit is contained in:
2026-10-15 19:27:45 +01:00
parent c636eb0803
commit 285f77a9e2
7 changed files with 62 additions and 11 deletions
+13
View File
@@ -16,6 +16,15 @@ fn reply(out: &mut impl Write, message: &Value, body: Value) {
);
}
/// Connect to `address`, send one line, and return the line that comes back.
fn tcp_line(address: &str, line: &str) -> io::Result<String> {
let mut stream = std::net::TcpStream::connect(address)?;
writeln!(stream, "{line}")?;
let mut answer = String::new();
io::BufReader::new(stream).read_line(&mut answer)?;
Ok(answer.trim_end().to_string())
}
fn io_error(error: io::Error) -> Value {
json!({"type": "error", "error": error.to_string()})
}
@@ -131,6 +140,10 @@ fn main() {
json!({"type": "armed"})
}
Some("ignore-stdin") => json!({"type": "ignoring"}),
Some("tcp") => match tcp_line(body["address"].as_str().unwrap_or_default(), text) {
Ok(line) => json!({"type": "tcp", "line": line}),
Err(error) => io_error(error),
},
Some("read") => match std::fs::read_to_string(&path) {
Ok(text) => json!({"type": "content", "text": text}),
Err(error) => io_error(error),