Use golang.org/x/sys/unix provided ioctl functions
This commit is contained in:
committed by
Cristian Maglie
parent
578b2ec832
commit
eb474d2569
2
go.mod
2
go.mod
@@ -5,5 +5,5 @@ go 1.13
|
|||||||
require (
|
require (
|
||||||
github.com/creack/goselect v0.1.1
|
github.com/creack/goselect v0.1.1
|
||||||
github.com/stretchr/testify v1.4.0
|
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
4
go.sum
@@ -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/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 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
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-20200909081042-eff7692f9009 h1:W0lCpv29Hv0UaM1LXb9QlBHLNP8UFfcKjblhVCWftOM=
|
||||||
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
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 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
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=
|
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"go.bug.st/serial/unixutils"
|
"go.bug.st/serial/unixutils"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
@@ -94,11 +93,11 @@ func (port *unixPort) Write(p []byte) (n int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (port *unixPort) ResetInputBuffer() 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 {
|
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 {
|
func (port *unixPort) SetMode(mode *Mode) error {
|
||||||
@@ -390,29 +389,25 @@ func setRawMode(settings *unix.Termios) {
|
|||||||
// native syscall wrapper functions
|
// native syscall wrapper functions
|
||||||
|
|
||||||
func (port *unixPort) getTermSettings() (*unix.Termios, error) {
|
func (port *unixPort) getTermSettings() (*unix.Termios, error) {
|
||||||
settings := &unix.Termios{}
|
return unix.IoctlGetTermios(port.handle, ioctlTcgetattr)
|
||||||
err := ioctl(port.handle, ioctlTcgetattr, uintptr(unsafe.Pointer(settings)))
|
|
||||||
return settings, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (port *unixPort) setTermSettings(settings *unix.Termios) error {
|
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) {
|
func (port *unixPort) getModemBitsStatus() (int, error) {
|
||||||
var status int
|
return unix.IoctlGetInt(port.handle, unix.TIOCMGET)
|
||||||
err := ioctl(port.handle, unix.TIOCMGET, uintptr(unsafe.Pointer(&status)))
|
|
||||||
return status, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (port *unixPort) setModemBitsStatus(status int) error {
|
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 {
|
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 {
|
func (port *unixPort) releaseExclusiveAccess() error {
|
||||||
return ioctl(port.handle, unix.TIOCNXCL, 0)
|
return unix.IoctlSetInt(port.handle, unix.TIOCNXCL, 0)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
|
||||||
@@ -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)
|
|
||||||
@@ -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)
|
|
||||||
@@ -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)
|
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user