Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send and receive WASI std IO as Erlang messages #392

Open
tessi opened this issue Jan 7, 2023 · 1 comment
Open

Send and receive WASI std IO as Erlang messages #392

tessi opened this issue Jan 7, 2023 · 1 comment

Comments

@tessi
Copy link
Owner

tessi commented Jan 7, 2023

@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 :)

@josevalim
Copy link

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

Oh, that sounds great too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants