summaryrefslogtreecommitdiff
path: root/src/internal
diff options
context:
space:
mode:
authorChris O'Hara <cohara87@gmail.com>2023-05-08 17:06:08 +1000
committerGopher Robot <gobot@golang.org>2023-05-11 23:29:04 +0000
commit41893389a6fb6d4d8b181cd90ca58d9d65326f76 (patch)
treef9636c4a2e3f1bfedbb60c413f6d6658bbbf4030 /src/internal
parent70247126415246c7716ec4d28d6bc1f4077aee1f (diff)
downloadgo-git-41893389a6fb6d4d8b181cd90ca58d9d65326f76.tar.gz
syscall: implement wasip1 SetNonblock and IsNonblock
Allows for the NONBLOCK file descriptor flag to be set and queried on wasip1. syscall.SetNonblock uses the fd_fdstat_set_flags WASI system call and unix.IsNonblock uses the fd_fdstat_get system call. This is a prerequisite for non-blocking I/O support. Change-Id: I2bf79fd57142b2ec53eed3977d9aac8c6337eb80 Reviewed-on: https://go-review.googlesource.com/c/go/+/493356 Auto-Submit: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Reviewed-by: Julien Fabre <ju.pryz@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Achille Roussel <achille.roussel@gmail.com>
Diffstat (limited to 'src/internal')
-rw-r--r--src/internal/syscall/unix/nonblocking_wasip1.go18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/internal/syscall/unix/nonblocking_wasip1.go b/src/internal/syscall/unix/nonblocking_wasip1.go
index 49a2a232ba..208db28c3e 100644
--- a/src/internal/syscall/unix/nonblocking_wasip1.go
+++ b/src/internal/syscall/unix/nonblocking_wasip1.go
@@ -6,6 +6,22 @@
package unix
+import (
+ "syscall"
+ _ "unsafe" // for go:linkname
+)
+
func IsNonblock(fd int) (nonblocking bool, err error) {
- return false, nil
+ flags, e1 := fd_fdstat_get_flags(fd)
+ if e1 != nil {
+ return false, e1
+ }
+ return flags&syscall.FDFLAG_NONBLOCK != 0, nil
}
+
+// This helper is implemented in the syscall package. It means we don't have
+// to redefine the fd_fdstat_get host import or the fdstat struct it
+// populates.
+//
+//go:linkname fd_fdstat_get_flags syscall.fd_fdstat_get_flags
+func fd_fdstat_get_flags(fd int) (uint32, error)