updated vendor
This commit is contained in:
+62
-9
@@ -7,11 +7,10 @@ import (
|
||||
"time"
|
||||
|
||||
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
|
||||
"github.com/tetratelabs/wazero/internal/fsapi"
|
||||
"github.com/tetratelabs/wazero/sys"
|
||||
)
|
||||
|
||||
func NewStdioFile(stdin bool, f fs.File) (fsapi.File, error) {
|
||||
func NewStdioFile(stdin bool, f fs.File) (experimentalsys.File, error) {
|
||||
// Return constant stat, which has fake times, but keep the underlying
|
||||
// file mode. Fake times are needed to pass wasi-testsuite.
|
||||
// https://github.com/WebAssembly/wasi-testsuite/blob/af57727/tests/rust/src/bin/fd_filestat_get.rs#L1-L19
|
||||
@@ -27,7 +26,7 @@ func NewStdioFile(stdin bool, f fs.File) (fsapi.File, error) {
|
||||
} else {
|
||||
flag = experimentalsys.O_WRONLY
|
||||
}
|
||||
var file fsapi.File
|
||||
var file experimentalsys.File
|
||||
if of, ok := f.(*os.File); ok {
|
||||
// This is ok because functions that need path aren't used by stdioFile
|
||||
file = newOsFile("", flag, 0, of)
|
||||
@@ -63,10 +62,37 @@ func OpenFSFile(fs fs.FS, path string, flag experimentalsys.Oflag, perm fs.FileM
|
||||
}
|
||||
|
||||
type stdioFile struct {
|
||||
fsapi.File
|
||||
experimentalsys.File
|
||||
st sys.Stat_t
|
||||
}
|
||||
|
||||
// IsNonblock implements experimentalsys.PollableFile by forwarding to the
|
||||
// underlying file if it supports it.
|
||||
func (f *stdioFile) IsNonblock() bool {
|
||||
if pf, ok := f.File.(experimentalsys.PollableFile); ok {
|
||||
return pf.IsNonblock()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// SetNonblock implements experimentalsys.PollableFile by forwarding to the
|
||||
// underlying file if it supports it.
|
||||
func (f *stdioFile) SetNonblock(enable bool) experimentalsys.Errno {
|
||||
if pf, ok := f.File.(experimentalsys.PollableFile); ok {
|
||||
return pf.SetNonblock(enable)
|
||||
}
|
||||
return experimentalsys.ENOSYS
|
||||
}
|
||||
|
||||
// Poll implements experimentalsys.Pollable by forwarding to the underlying file
|
||||
// if it supports polling.
|
||||
func (f *stdioFile) Poll(flag experimentalsys.Pflag, timeoutMillis int32) (ready bool, errno experimentalsys.Errno) {
|
||||
if p, ok := f.File.(experimentalsys.Pollable); ok {
|
||||
return p.Poll(flag, timeoutMillis)
|
||||
}
|
||||
return false, experimentalsys.ENOSYS
|
||||
}
|
||||
|
||||
// SetAppend implements File.SetAppend
|
||||
func (f *stdioFile) SetAppend(bool) experimentalsys.Errno {
|
||||
// Ignore for stdio.
|
||||
@@ -341,18 +367,45 @@ func (f *fsFile) close() experimentalsys.Errno {
|
||||
return experimentalsys.UnwrapOSError(f.file.Close())
|
||||
}
|
||||
|
||||
// IsNonblock implements the same method as documented on fsapi.File
|
||||
// nonblocker is a subset of PollableFile for checking non-blocking mode on
|
||||
// an fs.File. fs.File cannot implement PollableFile due to conflicting Close
|
||||
// signatures (error vs Errno), so we use this narrower interface.
|
||||
type nonblocker interface {
|
||||
IsNonblock() bool
|
||||
SetNonblock(enable bool) experimentalsys.Errno
|
||||
}
|
||||
|
||||
// IsNonblock implements experimentalsys.PollableFile by forwarding to the
|
||||
// underlying fs.File if it supports it.
|
||||
func (f *fsFile) IsNonblock() bool {
|
||||
if nb, ok := f.file.(nonblocker); ok {
|
||||
return nb.IsNonblock()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// SetNonblock implements the same method as documented on fsapi.File
|
||||
func (f *fsFile) SetNonblock(bool) experimentalsys.Errno {
|
||||
// SetNonblock implements experimentalsys.PollableFile by forwarding to the
|
||||
// underlying fs.File if it supports it.
|
||||
func (f *fsFile) SetNonblock(enable bool) experimentalsys.Errno {
|
||||
if nb, ok := f.file.(nonblocker); ok {
|
||||
return nb.SetNonblock(enable)
|
||||
}
|
||||
if !enable {
|
||||
return 0 // disabling nonblock on a file that doesn't support it is a no-op
|
||||
}
|
||||
return experimentalsys.ENOSYS
|
||||
}
|
||||
|
||||
// Poll implements the same method as documented on fsapi.File
|
||||
func (f *fsFile) Poll(fsapi.Pflag, int32) (ready bool, errno experimentalsys.Errno) {
|
||||
// Poll implements experimentalsys.Pollable by forwarding to the underlying
|
||||
// fs.File if it supports polling.
|
||||
//
|
||||
// Note: fsFile cannot implement PollableFile because fs.File and
|
||||
// experimentalsys.File have conflicting Close signatures (error vs Errno),
|
||||
// so no type can satisfy both. Pollable has no such conflict.
|
||||
func (f *fsFile) Poll(flag experimentalsys.Pflag, timeoutMillis int32) (ready bool, errno experimentalsys.Errno) {
|
||||
if p, ok := f.file.(experimentalsys.Pollable); ok {
|
||||
return p.Poll(flag, timeoutMillis)
|
||||
}
|
||||
return false, experimentalsys.ENOSYS
|
||||
}
|
||||
|
||||
|
||||
+5
-6
@@ -6,11 +6,10 @@ import (
|
||||
"os"
|
||||
|
||||
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
|
||||
"github.com/tetratelabs/wazero/internal/fsapi"
|
||||
"github.com/tetratelabs/wazero/sys"
|
||||
)
|
||||
|
||||
func newOsFile(path string, flag experimentalsys.Oflag, perm fs.FileMode, f *os.File) fsapi.File {
|
||||
func newOsFile(path string, flag experimentalsys.Oflag, perm fs.FileMode, f *os.File) experimentalsys.File {
|
||||
// On POSIX, if a file is removed from or added to the directory after the
|
||||
// most recent call to opendir() or rewinddir(), whether a subsequent call
|
||||
// to readdir() returns an entry for that file is unspecified.
|
||||
@@ -153,12 +152,12 @@ func (f *osFile) checkSameFile(osf *os.File) experimentalsys.Errno {
|
||||
return experimentalsys.ENOENT
|
||||
}
|
||||
|
||||
// IsNonblock implements the same method as documented on fsapi.File
|
||||
// IsNonblock implements the same method as documented on experimentalsys.PollableFile
|
||||
func (f *osFile) IsNonblock() bool {
|
||||
return isNonblock(f)
|
||||
}
|
||||
|
||||
// SetNonblock implements the same method as documented on fsapi.File
|
||||
// SetNonblock implements the same method as documented on experimentalsys.PollableFile
|
||||
func (f *osFile) SetNonblock(enable bool) (errno experimentalsys.Errno) {
|
||||
if enable {
|
||||
f.flag |= experimentalsys.O_NONBLOCK
|
||||
@@ -229,8 +228,8 @@ func (f *osFile) Seek(offset int64, whence int) (newOffset int64, errno experime
|
||||
return
|
||||
}
|
||||
|
||||
// Poll implements the same method as documented on fsapi.File
|
||||
func (f *osFile) Poll(flag fsapi.Pflag, timeoutMillis int32) (ready bool, errno experimentalsys.Errno) {
|
||||
// Poll implements the same method as documented on experimentalsys.Pollable
|
||||
func (f *osFile) Poll(flag experimentalsys.Pflag, timeoutMillis int32) (ready bool, errno experimentalsys.Errno) {
|
||||
return poll(f.fd, flag, timeoutMillis)
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -4,12 +4,11 @@ package sysfs
|
||||
|
||||
import (
|
||||
"github.com/tetratelabs/wazero/experimental/sys"
|
||||
"github.com/tetratelabs/wazero/internal/fsapi"
|
||||
)
|
||||
|
||||
// poll implements `Poll` as documented on sys.File via a file descriptor.
|
||||
func poll(fd uintptr, flag fsapi.Pflag, timeoutMillis int32) (ready bool, errno sys.Errno) {
|
||||
if flag != fsapi.POLLIN {
|
||||
func poll(fd uintptr, flag sys.Pflag, timeoutMillis int32) (ready bool, errno sys.Errno) {
|
||||
if flag != sys.POLLIN {
|
||||
return false, sys.ENOTSUP
|
||||
}
|
||||
fds := []pollFd{newPollFd(fd, _POLLIN, 0)}
|
||||
|
||||
+2
-3
@@ -4,10 +4,9 @@ package sysfs
|
||||
|
||||
import (
|
||||
"github.com/tetratelabs/wazero/experimental/sys"
|
||||
"github.com/tetratelabs/wazero/internal/fsapi"
|
||||
)
|
||||
|
||||
// poll implements `Poll` as documented on fsapi.File via a file descriptor.
|
||||
func poll(uintptr, fsapi.Pflag, int32) (bool, sys.Errno) {
|
||||
// poll implements `Poll` as documented on sys.File via a file descriptor.
|
||||
func poll(uintptr, sys.Pflag, int32) (bool, sys.Errno) {
|
||||
return false, sys.ENOSYS
|
||||
}
|
||||
|
||||
+7
-8
@@ -5,7 +5,6 @@ import (
|
||||
"os"
|
||||
|
||||
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
|
||||
"github.com/tetratelabs/wazero/internal/fsapi"
|
||||
socketapi "github.com/tetratelabs/wazero/internal/sock"
|
||||
"github.com/tetratelabs/wazero/sys"
|
||||
)
|
||||
@@ -71,13 +70,13 @@ func (f *tcpListenerFile) Addr() *net.TCPAddr {
|
||||
return f.tl.Addr().(*net.TCPAddr)
|
||||
}
|
||||
|
||||
// IsNonblock implements the same method as documented on fsapi.File
|
||||
// IsNonblock implements the same method as documented on experimentalsys.PollableFile
|
||||
func (f *tcpListenerFile) IsNonblock() bool {
|
||||
return f.nonblock
|
||||
}
|
||||
|
||||
// Poll implements the same method as documented on fsapi.File
|
||||
func (f *tcpListenerFile) Poll(flag fsapi.Pflag, timeoutMillis int32) (ready bool, errno experimentalsys.Errno) {
|
||||
// Poll implements the same method as documented on experimentalsys.Pollable
|
||||
func (f *tcpListenerFile) Poll(flag experimentalsys.Pflag, timeoutMillis int32) (ready bool, errno experimentalsys.Errno) {
|
||||
return false, experimentalsys.ENOSYS
|
||||
}
|
||||
|
||||
@@ -167,7 +166,7 @@ func (f *tcpConnFile) close() experimentalsys.Errno {
|
||||
return f.Shutdown(socketapi.SHUT_RDWR)
|
||||
}
|
||||
|
||||
// SetNonblock implements the same method as documented on fsapi.File
|
||||
// SetNonblock implements the same method as documented on experimentalsys.PollableFile
|
||||
func (f *tcpConnFile) SetNonblock(enabled bool) (errno experimentalsys.Errno) {
|
||||
f.nonblock = enabled
|
||||
_, errno = syscallConnControl(f.tc, func(fd uintptr) (int, experimentalsys.Errno) {
|
||||
@@ -176,12 +175,12 @@ func (f *tcpConnFile) SetNonblock(enabled bool) (errno experimentalsys.Errno) {
|
||||
return
|
||||
}
|
||||
|
||||
// IsNonblock implements the same method as documented on fsapi.File
|
||||
// IsNonblock implements the same method as documented on experimentalsys.PollableFile
|
||||
func (f *tcpConnFile) IsNonblock() bool {
|
||||
return f.nonblock
|
||||
}
|
||||
|
||||
// Poll implements the same method as documented on fsapi.File
|
||||
func (f *tcpConnFile) Poll(flag fsapi.Pflag, timeoutMillis int32) (ready bool, errno experimentalsys.Errno) {
|
||||
// Poll implements the same method as documented on experimentalsys.Pollable
|
||||
func (f *tcpConnFile) Poll(flag experimentalsys.Pflag, timeoutMillis int32) (ready bool, errno experimentalsys.Errno) {
|
||||
return false, experimentalsys.ENOSYS
|
||||
}
|
||||
|
||||
+2
-3
@@ -7,7 +7,6 @@ import (
|
||||
"syscall"
|
||||
|
||||
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
|
||||
"github.com/tetratelabs/wazero/internal/fsapi"
|
||||
socketapi "github.com/tetratelabs/wazero/internal/sock"
|
||||
)
|
||||
|
||||
@@ -15,7 +14,7 @@ import (
|
||||
func (f *tcpListenerFile) Accept() (socketapi.TCPConn, experimentalsys.Errno) {
|
||||
// Ensure we have an incoming connection, otherwise return immediately.
|
||||
if f.nonblock {
|
||||
if ready, errno := _pollSock(f.tl, fsapi.POLLIN, 0); !ready || errno != 0 {
|
||||
if ready, errno := _pollSock(f.tl, experimentalsys.POLLIN, 0); !ready || errno != 0 {
|
||||
return nil, experimentalsys.EAGAIN
|
||||
}
|
||||
}
|
||||
@@ -30,7 +29,7 @@ func (f *tcpListenerFile) Accept() (socketapi.TCPConn, experimentalsys.Errno) {
|
||||
}
|
||||
}
|
||||
|
||||
// SetNonblock implements the same method as documented on fsapi.File
|
||||
// SetNonblock implements the same method as documented on experimentalsys.PollableFile
|
||||
func (f *tcpListenerFile) SetNonblock(enabled bool) (errno experimentalsys.Errno) {
|
||||
f.nonblock = enabled
|
||||
_, errno = syscallConnControl(f.tl, func(fd uintptr) (int, experimentalsys.Errno) {
|
||||
|
||||
+2
-3
@@ -7,7 +7,6 @@ import (
|
||||
"syscall"
|
||||
|
||||
"github.com/tetratelabs/wazero/experimental/sys"
|
||||
"github.com/tetratelabs/wazero/internal/fsapi"
|
||||
socketapi "github.com/tetratelabs/wazero/internal/sock"
|
||||
)
|
||||
|
||||
@@ -18,9 +17,9 @@ func newTCPListenerFile(tl *net.TCPListener) socketapi.TCPSock {
|
||||
return newDefaultTCPListenerFile(tl)
|
||||
}
|
||||
|
||||
func _pollSock(conn syscall.Conn, flag fsapi.Pflag, timeoutMillis int32) (bool, sys.Errno) {
|
||||
func _pollSock(conn syscall.Conn, flag sys.Pflag, timeoutMillis int32) (bool, sys.Errno) {
|
||||
n, errno := syscallConnControl(conn, func(fd uintptr) (int, sys.Errno) {
|
||||
if ready, errno := poll(fd, fsapi.POLLIN, 0); !ready || errno != 0 {
|
||||
if ready, errno := poll(fd, sys.POLLIN, 0); !ready || errno != 0 {
|
||||
return -1, errno
|
||||
} else {
|
||||
return 0, errno
|
||||
|
||||
+14
-16
@@ -6,9 +6,7 @@ import (
|
||||
"net"
|
||||
"syscall"
|
||||
|
||||
"github.com/tetratelabs/wazero/experimental/sys"
|
||||
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
|
||||
"github.com/tetratelabs/wazero/internal/fsapi"
|
||||
socketapi "github.com/tetratelabs/wazero/internal/sock"
|
||||
)
|
||||
|
||||
@@ -24,28 +22,28 @@ type unsupportedSockFile struct {
|
||||
}
|
||||
|
||||
// Accept implements the same method as documented on socketapi.TCPSock
|
||||
func (f *unsupportedSockFile) Accept() (socketapi.TCPConn, sys.Errno) {
|
||||
return nil, sys.ENOSYS
|
||||
func (f *unsupportedSockFile) Accept() (socketapi.TCPConn, experimentalsys.Errno) {
|
||||
return nil, experimentalsys.ENOSYS
|
||||
}
|
||||
|
||||
func _pollSock(conn syscall.Conn, flag fsapi.Pflag, timeoutMillis int32) (bool, sys.Errno) {
|
||||
return false, sys.ENOTSUP
|
||||
func _pollSock(conn syscall.Conn, flag experimentalsys.Pflag, timeoutMillis int32) (bool, experimentalsys.Errno) {
|
||||
return false, experimentalsys.ENOTSUP
|
||||
}
|
||||
|
||||
func setNonblockSocket(fd uintptr, enabled bool) sys.Errno {
|
||||
return sys.ENOTSUP
|
||||
func setNonblockSocket(fd uintptr, enabled bool) experimentalsys.Errno {
|
||||
return experimentalsys.ENOTSUP
|
||||
}
|
||||
|
||||
func readSocket(fd uintptr, buf []byte) (int, sys.Errno) {
|
||||
return -1, sys.ENOTSUP
|
||||
func readSocket(fd uintptr, buf []byte) (int, experimentalsys.Errno) {
|
||||
return -1, experimentalsys.ENOTSUP
|
||||
}
|
||||
|
||||
func writeSocket(fd uintptr, buf []byte) (int, sys.Errno) {
|
||||
return -1, sys.ENOTSUP
|
||||
func writeSocket(fd uintptr, buf []byte) (int, experimentalsys.Errno) {
|
||||
return -1, experimentalsys.ENOTSUP
|
||||
}
|
||||
|
||||
func recvfrom(fd uintptr, buf []byte, flags int32) (n int, errno sys.Errno) {
|
||||
return -1, sys.ENOTSUP
|
||||
func recvfrom(fd uintptr, buf []byte, flags int32) (n int, errno experimentalsys.Errno) {
|
||||
return -1, experimentalsys.ENOTSUP
|
||||
}
|
||||
|
||||
// syscallConnControl extracts a syscall.RawConn from the given syscall.Conn and applies
|
||||
@@ -54,8 +52,8 @@ func recvfrom(fd uintptr, buf []byte, flags int32) (n int, errno sys.Errno) {
|
||||
// syscallConnControl streamlines the pattern of extracting the syscall.Rawconn,
|
||||
// invoking its syscall.RawConn.Control method, then handling properly the errors that may occur
|
||||
// within fn or returned by syscall.RawConn.Control itself.
|
||||
func syscallConnControl(conn syscall.Conn, fn func(fd uintptr) (int, experimentalsys.Errno)) (n int, errno sys.Errno) {
|
||||
return -1, sys.ENOTSUP
|
||||
func syscallConnControl(conn syscall.Conn, fn func(fd uintptr) (int, experimentalsys.Errno)) (n int, errno experimentalsys.Errno) {
|
||||
return -1, experimentalsys.ENOTSUP
|
||||
}
|
||||
|
||||
// Accept implements the same method as documented on socketapi.TCPSock
|
||||
|
||||
+2
-3
@@ -10,7 +10,6 @@ import (
|
||||
"golang.org/x/sys/windows"
|
||||
|
||||
"github.com/tetratelabs/wazero/experimental/sys"
|
||||
"github.com/tetratelabs/wazero/internal/fsapi"
|
||||
socketapi "github.com/tetratelabs/wazero/internal/sock"
|
||||
)
|
||||
|
||||
@@ -70,8 +69,8 @@ func setNonblockSocket(fd uintptr, enabled bool) sys.Errno {
|
||||
return sys.UnwrapOSError(errno)
|
||||
}
|
||||
|
||||
func _pollSock(conn syscall.Conn, flag fsapi.Pflag, timeoutMillis int32) (bool, sys.Errno) {
|
||||
if flag != fsapi.POLLIN {
|
||||
func _pollSock(conn syscall.Conn, flag sys.Pflag, timeoutMillis int32) (bool, sys.Errno) {
|
||||
if flag != sys.POLLIN {
|
||||
return false, sys.ENOTSUP
|
||||
}
|
||||
n, errno := syscallConnControl(conn, func(fd uintptr) (int, sys.Errno) {
|
||||
|
||||
Reference in New Issue
Block a user