Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use x/sys/unix rather than syscall. #124

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading