poll_oneoff only polled stdin for blocking fd read subscriptions,
silently dropping non-stdin pollable fds. Generalize the deferred
polling to poll each blocking fd individually, tracking remaining time
budget across iterations so total wall time never exceeds the requested
timeout.
Changes:
- Generalize poll_oneoff blocking fd handling: track each deferred
subscription's file and poll it individually instead of only stdin
- Track elapsed time per poll so N blocking fds complete within 1x
timeout
- Add test for poll_oneoff with non-stdin pollable fd
Fixes: #1500
Signed-off-by: Christian Stewart <christian@aperture.us>
On 32-bit platforms (e.g., ARM/v7), len(name) returns a 32-bit int. The
expression `uint64(len(name) << 32)` causes the shift to overflow to 0
before the uint64 cast, making fd_prestat_get report dir_name_len=0 for
preopened directories. This breaks all WASI filesystem operations
(mkdir, open, stat, etc.) with EBADF.
Fix: cast to uint64 before shifting — `uint64(len(name)) << 32`.
More: https://github.com/mimusic-org/mimusic/issues/29
Signed-off-by: 涵曦 <im.hanxi@gmail.com>
When using WithStdin() with a custom io.Reader, allow it to implement
Poll() for proper async I/O in poll_oneoff. Previously, only os.Stdin
(via NewStdioFile) had Poll support.
Add Pollable and PollableFile interfaces to experimental/sys so users
can implement polling on their custom readers and filesystems.
PollableFile extends File with Poll, IsNonblock, and SetNonblock without
modifying the existing File interface, avoiding breakage for downstream
File implementors.
As discussed in #2462, the current poll_oneoff implementation has
special handling for stdin but doesn't allow custom stdin
implementations to participate in polling. This prevents proper async
I/O when using custom readers (e.g., virtual terminals, networked I/O).
With these changes, users can now:
- Pass a custom io.Reader to WithStdin() implementing
experimental/sys.Pollable
- The poll_oneoff WASI function will call this implementation
- Implement experimental/sys.PollableFile for full file poll support
Changes:
- Add Pollable interface and Pflag type to experimental/sys
- Add PollableFile interface to experimental/sys (File + Pollable +
nonblock methods)
- Make internal/fsapi.File a type alias for
experimental/sys.PollableFile
- Add Pollable check in StdinFile.Poll() and fsFile.Poll()
- Check Pollable before POLLIN flag so impl. can handle non-POLLIN flags
- Re-export Pflag types from internal/fsapi via type aliases to
experimental/sys canonical definitions
- Add unit tests for Poll using in-memory files
Fixes#1500
---------
Signed-off-by: Christian Stewart <christian@aperture.us>
As discussed in #2434. This is just raising the minimum Go version, not
adding dependencies.
I fixed some deprecations that caused actual CI breakages, and adjusted
comments mentioning specific Go versions (also checked nothing important
changed).
Since I was touching the yaml file, I updated OS versions we test
against (for the BSD, etc).
Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>