Debian Codegraph @

tpmutil/poll_unix.go

raw
1 //go:build linux || darwin
2
3 package tpmutil
4
5 import (
6 "fmt"
7 "os"
8
9 "golang.org/x/sys/unix"
10 )
11
12 // poll blocks until the file descriptor is ready for reading or an error occurs.
13 func poll(f *os.File) error {
14 var (
15 fds = []unix.PollFd{{
16 Fd: int32(f.Fd()),
17 Events: 0x1, // POLLIN
18 }}
19 timeout = -1 // Indefinite timeout
20 )
21
22 if _, err := unix.Poll(fds, timeout); err != nil {
23 return err
24 }
25
26 // Revents is filled in by the kernel.
27 // If the expected event happened, Revents should match Events.
28 if fds[0].Revents != fds[0].Events {
29 return fmt.Errorf("unexpected poll Revents 0x%x", fds[0].Revents)
30 }
31 return nil
32 }