github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/cmds/core/elvish/sys/waitforread_unix.go (about) 1 // +build !windows,!plan9 2 3 package sys 4 5 import "os" 6 7 // WaitForRead blocks until any of the given files is ready to be read. It 8 // returns a boolean array indicating which files are ready to be read and 9 // possible errors. 10 // 11 // It is implemented with select(2) on Unix and WaitForMultipleObjects on 12 // Windows. 13 func WaitForRead(files ...*os.File) (ready []bool, err error) { 14 maxfd := 0 15 fdset := NewFdSet() 16 for _, file := range files { 17 fd := int(file.Fd()) 18 if maxfd < fd { 19 maxfd = fd 20 } 21 fdset.Set(fd) 22 } 23 err = Select(maxfd+1, fdset, nil, nil) 24 ready = make([]bool, len(files)) 25 for i, file := range files { 26 ready[i] = fdset.IsSet(int(file.Fd())) 27 } 28 return ready, err 29 }