generated from WebAssembly/wasi-proposal-template
-
Notifications
You must be signed in to change notification settings - Fork 17
Draft a prototype stdio design for wasip3. #75
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
Draft
sunfishcode
wants to merge
1
commit into
main
Choose a base branch
from
sunfishcode/stdio
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,74 @@ | ||
@since(version = 0.3.0) | ||
interface stdin { | ||
@since(version = 0.3.0) | ||
get-stdin: func() -> stream<u8>; | ||
use stdio.{error}; | ||
|
||
/// Reads data from a “standard input”. | ||
/// | ||
/// This function reads at most `amount` bytes from a | ||
/// “standard input” source. | ||
@since(version = 0.3.0) | ||
read: func(amount: u32) -> result<list<u8>, error>; | ||
} | ||
|
||
@since(version = 0.3.0) | ||
interface stdout { | ||
@since(version = 0.3.0) | ||
set-stdout: func(data: stream<u8>); | ||
use stdio.{error}; | ||
|
||
/// Writes data to a “standard output”. | ||
/// | ||
/// This function writes the bytes of `data` to a “standard output” | ||
/// destination. | ||
/// | ||
/// The data may be either text or binary; if it is text, it is recommended | ||
/// to be encoded as UTF-8, to allow terminal implementations on non-UTF-8 | ||
/// host environments to transcode it into their native text encoding. | ||
@since(version = 0.3.0) | ||
write: func(data: list<u8>) -> result<_, error>; | ||
} | ||
|
||
@since(version = 0.3.0) | ||
interface stderr { | ||
@since(version = 0.3.0) | ||
set-stderr: func(data: stream<u8>); | ||
use stdio.{error}; | ||
|
||
/// Writes data to a “standard error”. | ||
/// | ||
/// This function writes the bytes of `data` to a “standard error” | ||
/// destination. | ||
/// | ||
/// As with `stdout.write`, the data may be tierh text or binary, and | ||
/// if it is text, it is recommended to be encoded as UTF-8. | ||
@since(version = 0.3.0) | ||
write: func(data: list<u8>) -> result<_, error>; | ||
} | ||
|
||
/// Types common to the stdio interfaces. | ||
@since(version = 0.3.0) | ||
interface stdio { | ||
/// An error code for stdio functions. | ||
@since(version = 0.3.0) | ||
enum error { | ||
/// An I/O error occurred and the operation not completed successfully. | ||
/// | ||
/// After a `read` or `write` function has returned `io`, it thereafter | ||
/// always returns `io`. | ||
io, | ||
|
||
/// The other end was dropped and so this end must now be dropped. | ||
/// | ||
/// For `read`, this means the end of the stream has been reached. | ||
/// | ||
/// For `write`, this means that the consumer has no need for further | ||
/// data from this stream. This doesn't signify an error; it just | ||
/// instructs the producer to stop sending data. | ||
/// | ||
/// After a `read` or `write` function has returned `dropped`, it | ||
/// thereafter always returns `dropped`. | ||
dropped, | ||
} | ||
} | ||
|
||
// FIXME: Provide a way to keep reading after a `dropped`, for the `tail -f` idiom? | ||
|
||
// FIXME: Should write return the number of bytes written? | ||
|
||
// FIXME: How can we avoid the whole situation that caused wasip2 to have `check-write`? |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be async so you can avoid blocking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Async in Wit is just a hint, so you can avoid blocking either way, and the main question is what the default should be.
In my experience most programs that use stdin use it in a synchronous way, which suggests making it sync by default, but I don't have a strong opinion about it.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
many C programs use functions like
kbhit
orO_NONBLOCK
onstdin
, imo we should have support in the C library for stuff like that, afaict that requires the C library to use the async version even if most programs just block.