//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 }