File: poll_unix.go

package info (click to toggle)
golang-github-google-go-tpm 0.9.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,932 kB
  • sloc: makefile: 13
file content (32 lines) | stat: -rw-r--r-- 634 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//go:build linux || darwin

package tpmutil

import (
	"fmt"
	"os"

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

// poll blocks until the file descriptor is ready for reading or an error occurs.
func poll(f *os.File) error {
	var (
		fds = []unix.PollFd{{
			Fd:     int32(f.Fd()),
			Events: 0x1, // POLLIN
		}}
		timeout = -1 // Indefinite timeout
	)

	if _, err := unix.Poll(fds, timeout); err != nil {
		return err
	}

	// Revents is filled in by the kernel.
	// If the expected event happened, Revents should match Events.
	if fds[0].Revents != fds[0].Events {
		return fmt.Errorf("unexpected poll Revents 0x%x", fds[0].Revents)
	}
	return nil
}