diff options
author | Brady OBrien <brady.obrien128@gmail.com> | 2018-05-17 17:58:54 -0500 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-21 17:31:22 +0200 |
commit | b962d7d791bb13830d62d7ae326780b413463971 (patch) | |
tree | 0b0a27de77af3319bfd8115230688b46e07d5fb6 /rwcancel | |
parent | 837a12c84151968fac6477f75d6bcb52e7ae64db (diff) |
Add FreeBSD support
Signed-off-by: Brady OBrien <brady.obrien128@gmail.com>
Diffstat (limited to 'rwcancel')
-rw-r--r-- | rwcancel/fdset_default.go | 24 | ||||
-rw-r--r-- | rwcancel/fdset_freebsd.go | 22 | ||||
-rw-r--r-- | rwcancel/rwcancel.go (renamed from rwcancel/rwcancel_unix.go) | 26 | ||||
-rw-r--r-- | rwcancel/select_default.go (renamed from rwcancel/select_darwin.go) | 2 |
4 files changed, 54 insertions, 20 deletions
diff --git a/rwcancel/fdset_default.go b/rwcancel/fdset_default.go new file mode 100644 index 0000000..06e2695 --- /dev/null +++ b/rwcancel/fdset_default.go @@ -0,0 +1,24 @@ +// +build !freebsd + +/* SPDX-License-Identifier: GPL-2.0 + * + * Copyright (C) 2017-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. + */ + +package rwcancel + +import "golang.org/x/sys/unix" + +type fdSet struct { + fdset unix.FdSet +} + +func (fdset *fdSet) set(i int) { + bits := 32 << (^uint(0) >> 63) + fdset.fdset.Bits[i/bits] |= 1 << uint(i%bits) +} + +func (fdset *fdSet) check(i int) bool { + bits := 32 << (^uint(0) >> 63) + return (fdset.fdset.Bits[i/bits] & (1 << uint(i%bits))) != 0 +} diff --git a/rwcancel/fdset_freebsd.go b/rwcancel/fdset_freebsd.go new file mode 100644 index 0000000..39a7a4e --- /dev/null +++ b/rwcancel/fdset_freebsd.go @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * Copyright (C) 2017-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. + */ + +package rwcancel + +import "golang.org/x/sys/unix" + +type fdSet struct { + fdset unix.FdSet +} + +func (fdset *fdSet) set(i int) { + bits := 32 << (^uint(0) >> 63) + fdset.fdset.X__fds_bits[i/bits] |= 1 << uint(i%bits) +} + +func (fdset *fdSet) check(i int) bool { + bits := 32 << (^uint(0) >> 63) + return (fdset.fdset.X__fds_bits[i/bits] & (1 << uint(i%bits))) != 0 +} diff --git a/rwcancel/rwcancel_unix.go b/rwcancel/rwcancel.go index 739a8c3..aac743a 100644 --- a/rwcancel/rwcancel_unix.go +++ b/rwcancel/rwcancel.go @@ -12,26 +12,6 @@ import ( "syscall" ) -type RWCancel struct { - fd int - closingReader *os.File - closingWriter *os.File -} - -type fdSet struct { - fdset unix.FdSet -} - -func (fdset *fdSet) set(i int) { - bits := 32 << (^uint(0) >> 63) - fdset.fdset.Bits[i/bits] |= 1 << uint(i%bits) -} - -func (fdset *fdSet) check(i int) bool { - bits := 32 << (^uint(0) >> 63) - return (fdset.fdset.Bits[i/bits] & (1 << uint(i%bits))) != 0 -} - func max(a, b int) int { if a > b { return a @@ -39,6 +19,12 @@ func max(a, b int) int { return b } +type RWCancel struct { + fd int + closingReader *os.File + closingWriter *os.File +} + func NewRWCancel(fd int) (*RWCancel, error) { err := unix.SetNonblock(fd, true) if err != nil { diff --git a/rwcancel/select_darwin.go b/rwcancel/select_default.go index d14edc8..302a618 100644 --- a/rwcancel/select_darwin.go +++ b/rwcancel/select_default.go @@ -3,6 +3,8 @@ * Copyright (C) 2017-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. */ +// +build !linux + package rwcancel import "golang.org/x/sys/unix" |