-
Notifications
You must be signed in to change notification settings - Fork 259
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
Re-introduces internal fsapi.File with non-blocking methods #1613
Merged
Merged
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 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package fsapi | ||
|
||
import experimentalsys "github.com/tetratelabs/wazero/experimental/sys" | ||
|
||
// File includes methods not yet ready to document for end users, notably | ||
// non-blocking functionality. | ||
// | ||
// Particularly, Poll is subject to debate. For example, whether a user should | ||
// be able to choose how to implement timeout or not. Currently, this interface | ||
// allows the user to choose to sleep or use native polling, and which choice | ||
// they make impacts thread behavior as summarized here: | ||
// https://github.com/tetratelabs/wazero/pull/1606#issuecomment-1665475516 | ||
type File interface { | ||
experimentalsys.File | ||
|
||
// IsNonblock returns true if the file was opened with O_NONBLOCK, or | ||
// SetNonblock was successfully enabled on this file. | ||
// | ||
// # Notes | ||
// | ||
// - This might not match the underlying state of the file descriptor if | ||
// the file was not opened via OpenFile. | ||
IsNonblock() bool | ||
|
||
// SetNonblock toggles the non-blocking mode (O_NONBLOCK) of this file. | ||
// | ||
// # Errors | ||
// | ||
// A zero Errno is success. The below are expected otherwise: | ||
// - ENOSYS: the implementation does not support this function. | ||
// - EBADF: the file or directory was closed. | ||
// | ||
// # Notes | ||
// | ||
// - This is like syscall.SetNonblock and `fcntl` with O_NONBLOCK in | ||
// POSIX. See https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html | ||
SetNonblock(enable bool) experimentalsys.Errno | ||
|
||
// Poll returns if the file has data ready to be read or written. | ||
// | ||
// # Parameters | ||
// | ||
// The `flag` parameter determines which event to await, such as POLLIN, | ||
// POLLOUT, or a combination like `POLLIN|POLLOUT`. | ||
// | ||
// The `timeoutMillis` parameter is how long to block for an event, or | ||
// interrupted, in milliseconds. There are two special values: | ||
// - zero returns immediately | ||
// - any negative value blocks any amount of time | ||
// | ||
// # Results | ||
// | ||
// `ready` means there was data ready to read or written. False can mean no | ||
// event was ready or `errno` is not zero. | ||
// | ||
// A zero `errno` is success. The below are expected otherwise: | ||
// - ENOSYS: the implementation does not support this function. | ||
// - ENOTSUP: the implementation does not the flag combination. | ||
// - EINTR: the call was interrupted prior to an event. | ||
// | ||
// # Notes | ||
// | ||
// - This is like `poll` in POSIX, for a single file. | ||
// See https://pubs.opengroup.org/onlinepubs/9699919799/functions/poll.html | ||
// - No-op files, such as those which read from /dev/null, should return | ||
// immediately true, as data will never become available. | ||
// - See /RATIONALE.md for detailed notes including impact of blocking. | ||
Poll(flag Pflag, timeoutMillis int32) (ready bool, errno experimentalsys.Errno) | ||
} |
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package fsapi | ||
|
||
import experimentalsys "github.com/tetratelabs/wazero/experimental/sys" | ||
|
||
func Adapt(f experimentalsys.File) File { | ||
if f, ok := f.(File); ok { | ||
return f | ||
} | ||
return unimplementedFile{f} | ||
} | ||
|
||
type unimplementedFile struct{ experimentalsys.File } | ||
|
||
// IsNonblock implements File.IsNonblock | ||
func (unimplementedFile) IsNonblock() bool { | ||
return false | ||
} | ||
|
||
// SetNonblock implements File.SetNonblock | ||
func (unimplementedFile) SetNonblock(bool) experimentalsys.Errno { | ||
return experimentalsys.ENOSYS | ||
} | ||
|
||
// Poll implements File.Poll | ||
func (unimplementedFile) Poll(Pflag, int32) (ready bool, errno experimentalsys.Errno) { | ||
return false, experimentalsys.ENOSYS | ||
} |
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
the thing that tripped the whole debate was me noticing a PR that basically obviated this parameter based on concerns about blocking. Rather than get through that debate, which seems still murky, this moves the whole feature set internal. This allows users to still supply filesystems even though there remain plenty of blocking methods, such as Read.