Skip to content

Commit

Permalink
Use x/sys/unix rather than syscall. (#124)
Browse files Browse the repository at this point in the history
This makes our code more portable, and avoids the annoyance with
Select returning a different number of arguments as per the following
golang bug report:

* golang/go#34458
  • Loading branch information
skx authored Jun 19, 2024
1 parent f690c15 commit 0da3ab3
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 123 deletions.
26 changes: 0 additions & 26 deletions consolein/select_darwin.go

This file was deleted.

38 changes: 0 additions & 38 deletions consolein/select_freebsd.go

This file was deleted.

26 changes: 0 additions & 26 deletions consolein/select_netbsd.go

This file was deleted.

26 changes: 0 additions & 26 deletions consolein/select_openbsd.go

This file was deleted.

16 changes: 9 additions & 7 deletions consolein/select_linux.go → consolein/select_unix.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
//go:build linux
//go:build unix

package consolein

import (
"os"
"syscall"

"golang.org/x/sys/unix"
)

// canSelect contains a platform-specific implementation of code that tries to use
// SELECT to read from STDIN.
func canSelect() bool {

var readfds syscall.FdSet

fd := os.Stdin.Fd()
readfds.Bits[fd/64] |= 1 << (fd % 64)
fds := &unix.FdSet{}
fds.Set(int(os.Stdin.Fd()))

// See if input is pending, for a while.
nRead, err := syscall.Select(1, &readfds, nil, nil, &syscall.Timeval{Usec: 200})
tv := unix.Timeval{Usec: 200}

// via select with timeout
nRead, err := unix.Select(1, fds, nil, nil, &tv)
if err != nil {
return false
}
Expand Down

0 comments on commit 0da3ab3

Please sign in to comment.