forked from tetratelabs/wazero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
select.go
36 lines (33 loc) · 1.51 KB
/
select.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package sysfs
import (
"time"
"github.com/tetratelabs/wazero/internal/platform"
)
// _select exposes the select(2) syscall. This is named as such to avoid
// colliding with they keyword select while not exporting the function.
//
// # Notes on Parameters
//
// For convenience, we expose a pointer to a time.Duration instead of a pointer to a syscall.Timeval.
// It must be a pointer because `nil` means "wait forever".
//
// However, notice that select(2) may mutate the pointed Timeval on some platforms,
// for instance if the call returns early.
//
// This implementation *will not* update the pointed time.Duration value accordingly.
//
// See also: https://github.com/golang/sys/blob/master/unix/syscall_unix_test.go#L606-L617
//
// # Notes on the Syscall
//
// Because this is a blocking syscall, it will also block the carrier thread of the goroutine,
// preventing any means to support context cancellation directly.
//
// There are ways to obviate this issue. We outline here one idea, that is however not currently implemented.
// A common approach to support context cancellation is to add a signal file descriptor to the set,
// e.g. the read-end of a pipe or an eventfd on Linux.
// When the context is canceled, we may unblock a Select call by writing to the fd, causing it to return immediately.
// This however requires to do a bit of housekeeping to hide the "special" FD from the end-user.
func _select(n int, r, w, e *platform.FdSet, timeout *time.Duration) (int, error) {
return syscall_select(n, r, w, e, timeout)
}