From 41893389a6fb6d4d8b181cd90ca58d9d65326f76 Mon Sep 17 00:00:00 2001 From: Chris O'Hara Date: Mon, 8 May 2023 17:06:08 +1000 Subject: 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 Run-TryBot: Johan Brandhorst-Satzkorn Reviewed-by: Julien Fabre TryBot-Result: Gopher Robot Reviewed-by: Johan Brandhorst-Satzkorn Reviewed-by: Cherry Mui Reviewed-by: Ian Lance Taylor Reviewed-by: Achille Roussel --- src/internal/syscall/unix/nonblocking_wasip1.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/internal') 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) -- cgit v1.2.1