Tobias Kohlbau has uploaded this change for review.
windows: add support for CommTimeouts
CommTimeouts allows the user to set the timeout on Comm devices:
docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setcommtimeouts
docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getcommtimeouts
Change-Id: I756dc93b1b01412a496c6eccab22c9ff7e5f4b83
---
M windows/syscall_windows.go
M windows/types_windows.go
M windows/zsyscall_windows.go
3 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go
index 0197df8..5e03f4c 100644
--- a/windows/syscall_windows.go
+++ b/windows/syscall_windows.go
@@ -338,6 +338,8 @@
//sys SetProcessPriorityBoost(process Handle, disable bool) (err error) = kernel32.SetProcessPriorityBoost
//sys GetProcessWorkingSetSizeEx(hProcess Handle, lpMinimumWorkingSetSize *uintptr, lpMaximumWorkingSetSize *uintptr, flags *uint32)
//sys SetProcessWorkingSetSizeEx(hProcess Handle, dwMinimumWorkingSetSize uintptr, dwMaximumWorkingSetSize uintptr, flags uint32) (err error)
+//sys GetCommTimeouts(handle Handle, timeouts *CommTimeouts) (err error)
+//sys SetCommTimeouts(handle Handle, timeouts *CommTimeouts) (err error)
// Volume Management Functions
//sys DefineDosDevice(flags uint32, deviceName *uint16, targetPath *uint16) (err error) = DefineDosDeviceW
diff --git a/windows/types_windows.go b/windows/types_windows.go
index fd42607..2796fa5 100644
--- a/windows/types_windows.go
+++ b/windows/types_windows.go
@@ -2091,3 +2091,11 @@
// REG_NOTIFY_THREAD_AGNOSTIC indicates that the lifetime of the registration must not be tied to the lifetime of the thread issuing the RegNotifyChangeKeyValue call. Note: This flag value is only supported in Windows 8 and later.
REG_NOTIFY_THREAD_AGNOSTIC = 0x10000000
)
+
+type CommTimeouts struct {
+ ReadIntervalTimeout uint32
+ ReadTotalTimeoutMultiplier uint32
+ ReadTotalTimeoutConstant uint32
+ WriteTotalTimeoutMultiplier uint32
+ WriteTotalTimeoutConstant uint32
+}
diff --git a/windows/zsyscall_windows.go b/windows/zsyscall_windows.go
index c38c59d..51d0941 100644
--- a/windows/zsyscall_windows.go
+++ b/windows/zsyscall_windows.go
@@ -208,6 +208,7 @@
procFreeLibrary = modkernel32.NewProc("FreeLibrary")
procGenerateConsoleCtrlEvent = modkernel32.NewProc("GenerateConsoleCtrlEvent")
procGetACP = modkernel32.NewProc("GetACP")
+ procGetCommTimeouts = modkernel32.NewProc("GetCommTimeouts")
procGetCommandLineW = modkernel32.NewProc("GetCommandLineW")
procGetComputerNameExW = modkernel32.NewProc("GetComputerNameExW")
procGetComputerNameW = modkernel32.NewProc("GetComputerNameW")
@@ -291,6 +292,7 @@
procRemoveDirectoryW = modkernel32.NewProc("RemoveDirectoryW")
procResetEvent = modkernel32.NewProc("ResetEvent")
procResumeThread = modkernel32.NewProc("ResumeThread")
+ procSetCommTimeouts = modkernel32.NewProc("SetCommTimeouts")
procSetConsoleCursorPosition = modkernel32.NewProc("SetConsoleCursorPosition")
procSetConsoleMode = modkernel32.NewProc("SetConsoleMode")
procSetCurrentDirectoryW = modkernel32.NewProc("SetCurrentDirectoryW")
@@ -1744,6 +1746,14 @@
return
}
+func GetCommTimeouts(handle Handle, timeouts *CommTimeouts) (err error) {
+ r1, _, e1 := syscall.Syscall(procGetCommTimeouts.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(timeouts)), 0)
+ if r1 == 0 {
+ err = errnoErr(e1)
+ }
+ return
+}
+
func GetCommandLine() (cmd *uint16) {
r0, _, _ := syscall.Syscall(procGetCommandLineW.Addr(), 0, 0, 0, 0)
cmd = (*uint16)(unsafe.Pointer(r0))
@@ -2486,6 +2496,14 @@
return
}
+func SetCommTimeouts(handle Handle, timeouts *CommTimeouts) (err error) {
+ r1, _, e1 := syscall.Syscall(procSetCommTimeouts.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(timeouts)), 0)
+ if r1 == 0 {
+ err = errnoErr(e1)
+ }
+ return
+}
+
func setConsoleCursorPosition(console Handle, position uint32) (err error) {
r1, _, e1 := syscall.Syscall(procSetConsoleCursorPosition.Addr(), 2, uintptr(console), uintptr(position), 0)
if r1 == 0 {
To view, visit change 290209. To unsubscribe, or for help writing mail filters, visit settings.
1 comment:
Patchset:
I've used change I57fb4f1877a5fb7629809e79111cbfa02b11cca3 as a reference to add new windows functions into the sys package.
If something is at the wrong place or needs changes please let me know 😊
To view, visit change 290209. To unsubscribe, or for help writing mail filters, visit settings.