Skip to content

Send and receive WASI std IO as Erlang messages #392

@tessi

Description

@tessi

@josevalim came up with a great question:

Is the pipe the only way to interact with stdin/stdout/stderr? Or could it be streaming by default (i.e. send those as regular Erlang messages)?

And I love the idea, turning a WASM instance into a much more Elixir'y thing. I believe we want to send/receive raw binary's (no String, no concept of a "line").

With that, implementing a GenServer that receives stdin is fairly easy - it would take ownership of the stdin Wasmex.Pipe and write any received message into the pipe. We could optimize the pipe into an "input only" pipe - so we don't keep all input around forever as we do now, but that's an implementation detail. We probably want to configure Wasmex.Wasi.WasiOptions in a nice way for this new kind of input.

Implementing outputs (stdout, stderr) is slightly more advanced. We would need to implement a new kind of "output pipe" which sends erlang messages to a predefined pid, instead of writing the bytes to a memory buffer. We might want to implement buffering for efficiency - or maybe not, offloading that responsibility to the WASM binary (they should buffer their writes as they see fit).


José further wrote:

for stdin you would need buffer/queue, as you would to buffer data not yet read or block the reader until the buffer is available.

But if you can keep it as messages, then you can do reads/writes cross nodes, which is interesting too

which I didn't quite understand 😅 Why can't I just write any incoming message into the pipes memory buffer?

Anyhow, José promised to open this ticket after he had the time to look around. I went forward and already opened it, just in case. I love the idea and don't want to forget it :)
@josevalim: Feel free to still open "your" ticket if this doesn't reflect what you had in mind -- or we just adapt this ticket :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions