windows: add GetOverlappedResult function for async I/O
We already have all the structs and constants for async I/O, and the
various functions of x/sys/windows take the right parameters. But we're
missing the final step of any ordinary async I/O routine: getting the
result of overlapped I/O. Without this, the rest of the plumbing
supported by this module isn't actually so useful. So add this small
oversight.
Change-Id: I0ce1a71bce06bc81a83f3b0ca10ad9c4b67af726
Reviewed-on: https://go-review.googlesource.com/c/sys/+/168521
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/windows/zsyscall_windows.go b/windows/zsyscall_windows.go
index 75dcd27..eb9f062 100644
--- a/windows/zsyscall_windows.go
+++ b/windows/zsyscall_windows.go
@@ -77,6 +77,7 @@
procCreateFileW = modkernel32.NewProc("CreateFileW")
procReadFile = modkernel32.NewProc("ReadFile")
procWriteFile = modkernel32.NewProc("WriteFile")
+ procGetOverlappedResult = modkernel32.NewProc("GetOverlappedResult")
procSetFilePointer = modkernel32.NewProc("SetFilePointer")
procCloseHandle = modkernel32.NewProc("CloseHandle")
procGetStdHandle = modkernel32.NewProc("GetStdHandle")
@@ -654,6 +655,24 @@
return
}
+func GetOverlappedResult(handle Handle, overlapped *Overlapped, done *uint32, wait bool) (err error) {
+ var _p0 uint32
+ if wait {
+ _p0 = 1
+ } else {
+ _p0 = 0
+ }
+ r1, _, e1 := syscall.Syscall6(procGetOverlappedResult.Addr(), 4, uintptr(handle), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(done)), uintptr(_p0), 0, 0)
+ if r1 == 0 {
+ if e1 != 0 {
+ err = errnoErr(e1)
+ } else {
+ err = syscall.EINVAL
+ }
+ }
+ return
+}
+
func SetFilePointer(handle Handle, lowoffset int32, highoffsetptr *int32, whence uint32) (newlowoffset uint32, err error) {
r0, _, e1 := syscall.Syscall6(procSetFilePointer.Addr(), 4, uintptr(handle), uintptr(lowoffset), uintptr(unsafe.Pointer(highoffsetptr)), uintptr(whence), 0, 0)
newlowoffset = uint32(r0)