You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
529 B
23 lines
529 B
//go:build linux
|
|
|
|
package serial
|
|
|
|
import (
|
|
"io"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
// pendingSerialInput prevents a blocking Read on WCH drivers that do not
|
|
// consistently honor O_NONBLOCK. TIOCINQ is an immediate queue-length query.
|
|
func pendingSerialInput(device io.ReadWriteCloser) (int, bool, error) {
|
|
provider, ok := device.(interface{ Fd() uintptr })
|
|
if !ok {
|
|
return 0, false, nil
|
|
}
|
|
pending, err := unix.IoctlGetInt(int(provider.Fd()), unix.TIOCINQ)
|
|
if err != nil {
|
|
return 0, true, err
|
|
}
|
|
return pending, true, nil
|
|
}
|
|
|