Files
wazero/internal/platform/fdset.go
Edoardo Vacchi ea336061c2
Some checks failed
Release CLI / Pre-release build (push) Has been cancelled
Release CLI / Pre-release test (macos-12) (push) Has been cancelled
Release CLI / Pre-release test (ubuntu-22.04) (push) Has been cancelled
Release CLI / Pre-release test (windows-2022) (push) Has been cancelled
Release CLI / Release (push) Has been cancelled
wasi: introduce platform.Select and use it for poll_oneoff (#1346)
The PR introduces the `platform.Select()` API, wrapping `select(2)` on POSIX and emulated in some cases on Windows. RATIONALE.md contains a full explanation of the approach followed in `poll_oneoff` to handle Stdin and the other types of file descriptors, and the clock subscriptions.

It also introduces an abstraction (`StdioFilePoller`) to allow the simulation of different scenarios (waiting for input, input ready, timeout expired, etc.) when unit-testing interactive input.

This closes #1317.

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-04-18 16:31:34 +02:00

24 lines
515 B
Go

package platform
// Set adds the given fd to the set.
func (f *FdSet) Set(fd int) {
f.Bits[fd/nfdbits] |= (1 << (uintptr(fd) % nfdbits))
}
// Clear removes the given fd from the set.
func (f *FdSet) Clear(fd int) {
f.Bits[fd/nfdbits] &^= (1 << (uintptr(fd) % nfdbits))
}
// IsSet returns true when fd is in the set.
func (f *FdSet) IsSet(fd int) bool {
return f.Bits[fd/nfdbits]&(1<<(uintptr(fd)%nfdbits)) != 0
}
// Zero clears the set.
func (f *FdSet) Zero() {
for i := range f.Bits {
f.Bits[i] = 0
}
}