diff options
author | Simon Rozman <simon@rozman.si> | 2019-03-20 21:45:40 +0100 |
---|---|---|
committer | Simon Rozman <simon@rozman.si> | 2019-03-21 00:56:45 +0100 |
commit | 91b4e909bb5fe6980ec56983247e2bfb9fb70ee6 (patch) | |
tree | ff282bf8eba704fdbb861d3fb4fce579439d9e11 /tun/ztun_windows.go | |
parent | 2c51d6af48b8c6115852d72759c64aaaae5007d5 (diff) |
wintun: Use native Win32 API for I/O
Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'tun/ztun_windows.go')
-rw-r--r-- | tun/ztun_windows.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tun/ztun_windows.go b/tun/ztun_windows.go new file mode 100644 index 0000000..ed779c1 --- /dev/null +++ b/tun/ztun_windows.go @@ -0,0 +1,61 @@ +// Code generated by 'go generate'; DO NOT EDIT. + +package tun + +import ( + "syscall" + "unsafe" + + "golang.org/x/sys/windows" +) + +var _ unsafe.Pointer + +// Do the interface allocations only once for common +// Errno values. +const ( + errnoERROR_IO_PENDING = 997 +) + +var ( + errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING) +) + +// errnoErr returns common boxed Errno values, to prevent +// allocations at runtime. +func errnoErr(e syscall.Errno) error { + switch e { + case 0: + return nil + case errnoERROR_IO_PENDING: + return errERROR_IO_PENDING + } + // TODO: add more here, after collecting data on the common + // error values see on Windows. (perhaps when running + // all.bat?) + return e +} + +var ( + modkernel32 = windows.NewLazySystemDLL("kernel32.dll") + + procGetOverlappedResult = modkernel32.NewProc("GetOverlappedResult") +) + +func getOverlappedResult(handle windows.Handle, overlapped *windows.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 +} |