mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-02 07:07:33 -04:00
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 Reviewed-on: https://go-review.googlesource.com/c/sys/+/290209 Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Trust: Jason A. Donenfeld <Jason@zx2c4.com> Trust: Alex Brainman <alex.brainman@gmail.com> Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
committed by
Alex Brainman
parent
b0d1d43c01
commit
479acdf4ea
@@ -344,6 +344,8 @@ func NewCallbackCDecl(fn interface{}) uintptr {
|
|||||||
//sys SetProcessPriorityBoost(process Handle, disable bool) (err error) = kernel32.SetProcessPriorityBoost
|
//sys SetProcessPriorityBoost(process Handle, disable bool) (err error) = kernel32.SetProcessPriorityBoost
|
||||||
//sys GetProcessWorkingSetSizeEx(hProcess Handle, lpMinimumWorkingSetSize *uintptr, lpMaximumWorkingSetSize *uintptr, flags *uint32)
|
//sys GetProcessWorkingSetSizeEx(hProcess Handle, lpMinimumWorkingSetSize *uintptr, lpMaximumWorkingSetSize *uintptr, flags *uint32)
|
||||||
//sys SetProcessWorkingSetSizeEx(hProcess Handle, dwMinimumWorkingSetSize uintptr, dwMaximumWorkingSetSize uintptr, flags uint32) (err error)
|
//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
|
// Volume Management Functions
|
||||||
//sys DefineDosDevice(flags uint32, deviceName *uint16, targetPath *uint16) (err error) = DefineDosDeviceW
|
//sys DefineDosDevice(flags uint32, deviceName *uint16, targetPath *uint16) (err error) = DefineDosDeviceW
|
||||||
|
|||||||
@@ -2260,3 +2260,11 @@ const (
|
|||||||
// 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 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
|
REG_NOTIFY_THREAD_AGNOSTIC = 0x10000000
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type CommTimeouts struct {
|
||||||
|
ReadIntervalTimeout uint32
|
||||||
|
ReadTotalTimeoutMultiplier uint32
|
||||||
|
ReadTotalTimeoutConstant uint32
|
||||||
|
WriteTotalTimeoutMultiplier uint32
|
||||||
|
WriteTotalTimeoutConstant uint32
|
||||||
|
}
|
||||||
|
|||||||
@@ -212,6 +212,7 @@ var (
|
|||||||
procFreeLibrary = modkernel32.NewProc("FreeLibrary")
|
procFreeLibrary = modkernel32.NewProc("FreeLibrary")
|
||||||
procGenerateConsoleCtrlEvent = modkernel32.NewProc("GenerateConsoleCtrlEvent")
|
procGenerateConsoleCtrlEvent = modkernel32.NewProc("GenerateConsoleCtrlEvent")
|
||||||
procGetACP = modkernel32.NewProc("GetACP")
|
procGetACP = modkernel32.NewProc("GetACP")
|
||||||
|
procGetCommTimeouts = modkernel32.NewProc("GetCommTimeouts")
|
||||||
procGetCommandLineW = modkernel32.NewProc("GetCommandLineW")
|
procGetCommandLineW = modkernel32.NewProc("GetCommandLineW")
|
||||||
procGetComputerNameExW = modkernel32.NewProc("GetComputerNameExW")
|
procGetComputerNameExW = modkernel32.NewProc("GetComputerNameExW")
|
||||||
procGetComputerNameW = modkernel32.NewProc("GetComputerNameW")
|
procGetComputerNameW = modkernel32.NewProc("GetComputerNameW")
|
||||||
@@ -296,6 +297,7 @@ var (
|
|||||||
procRemoveDirectoryW = modkernel32.NewProc("RemoveDirectoryW")
|
procRemoveDirectoryW = modkernel32.NewProc("RemoveDirectoryW")
|
||||||
procResetEvent = modkernel32.NewProc("ResetEvent")
|
procResetEvent = modkernel32.NewProc("ResetEvent")
|
||||||
procResumeThread = modkernel32.NewProc("ResumeThread")
|
procResumeThread = modkernel32.NewProc("ResumeThread")
|
||||||
|
procSetCommTimeouts = modkernel32.NewProc("SetCommTimeouts")
|
||||||
procSetConsoleCursorPosition = modkernel32.NewProc("SetConsoleCursorPosition")
|
procSetConsoleCursorPosition = modkernel32.NewProc("SetConsoleCursorPosition")
|
||||||
procSetConsoleMode = modkernel32.NewProc("SetConsoleMode")
|
procSetConsoleMode = modkernel32.NewProc("SetConsoleMode")
|
||||||
procSetCurrentDirectoryW = modkernel32.NewProc("SetCurrentDirectoryW")
|
procSetCurrentDirectoryW = modkernel32.NewProc("SetCurrentDirectoryW")
|
||||||
@@ -1787,6 +1789,14 @@ func GetACP() (acp uint32) {
|
|||||||
return
|
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) {
|
func GetCommandLine() (cmd *uint16) {
|
||||||
r0, _, _ := syscall.Syscall(procGetCommandLineW.Addr(), 0, 0, 0, 0)
|
r0, _, _ := syscall.Syscall(procGetCommandLineW.Addr(), 0, 0, 0, 0)
|
||||||
cmd = (*uint16)(unsafe.Pointer(r0))
|
cmd = (*uint16)(unsafe.Pointer(r0))
|
||||||
@@ -2537,6 +2547,14 @@ func ResumeThread(thread Handle) (ret uint32, err error) {
|
|||||||
return
|
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) {
|
func setConsoleCursorPosition(console Handle, position uint32) (err error) {
|
||||||
r1, _, e1 := syscall.Syscall(procSetConsoleCursorPosition.Addr(), 2, uintptr(console), uintptr(position), 0)
|
r1, _, e1 := syscall.Syscall(procSetConsoleCursorPosition.Addr(), 2, uintptr(console), uintptr(position), 0)
|
||||||
if r1 == 0 {
|
if r1 == 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user