Use golang.org/x/sys/unix provided ioctl functions

This commit is contained in:
Maddie Zhan
2020-09-10 16:57:12 +08:00
committed by Cristian Maglie
parent 578b2ec832
commit eb474d2569
11 changed files with 11 additions and 136 deletions

2
go.mod
View File

@@ -5,5 +5,5 @@ go 1.13
require (
github.com/creack/goselect v0.1.1
github.com/stretchr/testify v1.4.0
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009
)

4
go.sum
View File

@@ -7,8 +7,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 h1:ZBzSG/7F4eNKz2L3GE9o300RX0Az1Bw5HF7PDraD+qU=
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 h1:W0lCpv29Hv0UaM1LXb9QlBHLNP8UFfcKjblhVCWftOM=
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=

View File

@@ -14,7 +14,6 @@ import (
"strings"
"sync"
"sync/atomic"
"unsafe"
"go.bug.st/serial/unixutils"
"golang.org/x/sys/unix"
@@ -94,11 +93,11 @@ func (port *unixPort) Write(p []byte) (n int, err error) {
}
func (port *unixPort) ResetInputBuffer() error {
return ioctl(port.handle, ioctlTcflsh, unix.TCIFLUSH)
return unix.IoctlSetInt(port.handle, ioctlTcflsh, unix.TCIFLUSH)
}
func (port *unixPort) ResetOutputBuffer() error {
return ioctl(port.handle, ioctlTcflsh, unix.TCOFLUSH)
return unix.IoctlSetInt(port.handle, ioctlTcflsh, unix.TCOFLUSH)
}
func (port *unixPort) SetMode(mode *Mode) error {
@@ -390,29 +389,25 @@ func setRawMode(settings *unix.Termios) {
// native syscall wrapper functions
func (port *unixPort) getTermSettings() (*unix.Termios, error) {
settings := &unix.Termios{}
err := ioctl(port.handle, ioctlTcgetattr, uintptr(unsafe.Pointer(settings)))
return settings, err
return unix.IoctlGetTermios(port.handle, ioctlTcgetattr)
}
func (port *unixPort) setTermSettings(settings *unix.Termios) error {
return ioctl(port.handle, ioctlTcsetattr, uintptr(unsafe.Pointer(settings)))
return unix.IoctlSetTermios(port.handle, ioctlTcsetattr, settings)
}
func (port *unixPort) getModemBitsStatus() (int, error) {
var status int
err := ioctl(port.handle, unix.TIOCMGET, uintptr(unsafe.Pointer(&status)))
return status, err
return unix.IoctlGetInt(port.handle, unix.TIOCMGET)
}
func (port *unixPort) setModemBitsStatus(status int) error {
return ioctl(port.handle, unix.TIOCMSET, uintptr(unsafe.Pointer(&status)))
return unix.IoctlSetPointerInt(port.handle, unix.TIOCMSET, status)
}
func (port *unixPort) acquireExclusiveAccess() error {
return ioctl(port.handle, unix.TIOCEXCL, 0)
return unix.IoctlSetInt(port.handle, unix.TIOCEXCL, 0)
}
func (port *unixPort) releaseExclusiveAccess() error {
return ioctl(port.handle, unix.TIOCNXCL, 0)
return unix.IoctlSetInt(port.handle, unix.TIOCNXCL, 0)
}

View File

@@ -1,9 +0,0 @@
//
// Copyright 2014-2020 Cristian Maglie. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
package serial
//sys ioctl(fd int, req uint64, data uintptr) (err error)

View File

@@ -1,9 +0,0 @@
//
// Copyright 2014-2020 Cristian Maglie. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
package serial
//sys ioctl(fd int, req uint64, data uintptr) (err error)

View File

@@ -1,9 +0,0 @@
//
// Copyright 2014-2020 Cristian Maglie. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
package serial
//sys ioctl(fd int, req uint64, data uintptr) (err error)

View File

@@ -1,9 +0,0 @@
//
// Copyright 2014-2020 Cristian Maglie. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
package serial
//sys ioctl(fd int, req uint64, data uintptr) (err error)

View File

@@ -1,21 +0,0 @@
//
// Copyright 2014-2020 Cristian Maglie. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
// This file is machine generated by the command:
// mksyscall.pl serial_darwin.go
// The generated stub is modified to make it compile under the "serial" package
package serial
import "golang.org/x/sys/unix"
func ioctl(fd int, req uint64, data uintptr) (err error) {
_, _, e1 := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(data))
if e1 != 0 {
err = e1
}
return
}

View File

@@ -1,21 +0,0 @@
//
// Copyright 2014-2020 Cristian Maglie. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
// This file is machine generated by the command:
// mksyscall.pl serial_freebsd.go
// The generated stub is modified to make it compile under the "serial" package
package serial
import "golang.org/x/sys/unix"
func ioctl(fd int, req uint64, data uintptr) (err error) {
_, _, e1 := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(data))
if e1 != 0 {
err = e1
}
return
}

View File

@@ -1,21 +0,0 @@
//
// Copyright 2014-2020 Cristian Maglie. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
// This file is machine generated by the command:
// mksyscall.pl serial_linux.go
// The generated stub is modified to make it compile under the "serial" package
package serial
import "golang.org/x/sys/unix"
func ioctl(fd int, req uint64, data uintptr) (err error) {
_, _, e1 := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(data))
if e1 != 0 {
err = e1
}
return
}

View File

@@ -1,21 +0,0 @@
//
// Copyright 2014-2020 Cristian Maglie. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
// This file is machine generated by the command:
// mksyscall.pl serial_openbsd.go
// The generated stub is modified to make it compile under the "serial" package
package serial
import "syscall"
func ioctl(fd int, req uint64, data uintptr) (err error) {
_, _, e1 := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(data))
if e1 != 0 {
err = e1
}
return
}