Skip to content
New issue

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

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

Already on GitHub? # to your account

replace MyStd{in|out}Stream with shareable streams #1982

Merged
merged 1 commit into from
Oct 27, 2023

Conversation

dicej
Copy link
Contributor

@dicej dicej commented Oct 27, 2023

MyStd{in|out}Stream were written based on the assumption that Std{in|out}Stream::stream would only ever be called once. Turns out that's not true for guest components which are composed of multiple subcomponents, since each subcomponent will potentially want its own handle, so they need to be shareable. The easiest way to do that is provide cloneable implementations of Host{In|Out}putStream which operate synchronously.

Note that this amounts to doing synchronous I/O in an asynchronous context, which we'd normally prefer to avoid, but the properly asynchronous implementations Host{In|Out}putStream based on AsyncRead/AsyncWrite are quite hairy and probably not worth it for "normal" stdio streams in Spin. If this does prove to be a performance bottleneck, though, we can certainly revisit it.

`MyStd{in|out}Stream` were written based on the assumption that
`Std{in|out}Stream::stream` would only ever be called once.  Turns out that's
not true for guest components which are composed of multiple subcomponents,
since each subcomponent will potentially want its own handle, so they need to be
shareable.  The easiest way to do that is provide cloneable implementations of
`Host{In|Out}putStream` which operate synchronously.

Note that this amounts to doing synchronous I/O in an asynchronous context,
which we'd normally prefer to avoid, but the properly asynchronous
implementations `Host{In|Out}putStream` based on `AsyncRead`/`AsyncWrite` are
quite hairy and probably not worth it for "normal" stdio streams in Spin.  If
this does prove to be a performance bottleneck, though, we can certainly revisit
it.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
@dicej dicej requested a review from fibonacci1729 October 27, 2023 20:54
@dicej dicej merged commit 8bafcb2 into fermyon:main Oct 27, 2023
9 checks passed
@dicej dicej deleted the shareable-stdio branch October 27, 2023 22:45
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants