unix: add methods to manipulate *FdSet

Add Set, Clear, IsSet and Zero methods to manipulate an *FdSet. These
implement the same functionality as the FD_SET, FD_CLR, FD_ISSET and
FD_ZERO macros in <sys/select.h>.

Change-Id: I6b7bccb98e58ee5e719096ed5743f6edcd232840
Reviewed-on: https://go-review.googlesource.com/c/sys/+/205397
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Tobias Klauser
2019-11-05 09:23:58 +01:00
committed by Tobias Klauser
parent e8c54fb511
commit ac3223d801
5 changed files with 91 additions and 12 deletions

View File

@@ -52,11 +52,10 @@ func TestSelect(t *testing.T) {
}
rFdSet := &unix.FdSet{}
fd := rr.Fd()
// FD_SET(fd, rFdSet)
rFdSet.Bits[fd/unix.NFDBITS] |= (1 << (fd % unix.NFDBITS))
fd := int(rr.Fd())
rFdSet.Set(fd)
n, err = unix.Select(int(fd+1), rFdSet, nil, nil, nil)
n, err = unix.Select(fd+1, rFdSet, nil, nil, nil)
if err != nil {
t.Fatalf("Select: %v", err)
}