Description
Proposal Details
Passing syscall.O_NONBLOCK
(only defined on Unix OSes) to os.Open
opens the file descriptor in nonblocking mode. This flag is mostly useful when working with named pipes, as they are normally used for asynchronous inter-process communication. There are 680 hits of syscall.O_NONBLOCK
on GitHub (prompt).
It is currently not possible to use the os
package to open a named pipe for non-blocking I/O (aka overlapped I/O) on Windows, as the syscall
package doesn't define O_NONBLOCK
on that port.
The os
package will start supporting overlapped I/O starting in Go 1.25 (see CL 661795 and #19098), yet there will be no way to open a file for overlapped I/O without using the x/sys/windows
(or syscall
) packages. Note that, on Windows, it is not possible to change a file descriptor to be non-blocking once it has been created, that property must be specified up-front.
I propose to promote syscall.O_NONBLOCK
to the os
package and map it to FILE_FLAG_OVERLAPPED
on Windows. We could also just define syscall.O_NONBLOCK
for Windows, but the syscall
API is frozen and IMO that flag makes sense to be in the os
package, as it will now be portable across most of the supported OSes (except on plan9 and wasi?).
--
Edit: Updated proposal:
package syscall
const O_OVERLAPPED = 0x04000 // the file or device is being opened or created for asynchronous I/O.
This const will also be added to golang.org/x/sys/windows.
See #73676 (comment).
@golang/windows @golang/proposal-review
Metadata
Metadata
Assignees
Type
Projects
Status