Permalink
Please sign in to comment.
Browse files
Fix FreeBSD build (#382)
FdSet.Bits is very weird here for some reason
- Loading branch information...
Showing
with
72 additions
and 2 deletions.
- +2 −0 sys/select.go
- +1 −1 sys/select_32.go
- +1 −1 sys/select_64.go
- +42 −0 sys/select_freebsd.go
- +13 −0 sys/select_freebsd_32.go
- +13 −0 sys/select_freebsd_64.go
| @@ -0,0 +1,42 @@ | ||
| // +build freebsd | ||
| // For whatever reason, it's X__fds_bits instead of Bits on FreeBSD | ||
| package sys | ||
| import "syscall" | ||
| type FdSet syscall.FdSet | ||
| func (fs *FdSet) s() *syscall.FdSet { | ||
| return (*syscall.FdSet)(fs) | ||
| } | ||
| func NewFdSet(fds ...int) *FdSet { | ||
| fs := &FdSet{} | ||
| fs.Set(fds...) | ||
| return fs | ||
| } | ||
| func (fs *FdSet) Clear(fds ...int) { | ||
| for _, fd := range fds { | ||
| idx, bit := index(fd) | ||
| fs.X__fds_bits[idx] &= ^bit | ||
| } | ||
| } | ||
| func (fs *FdSet) IsSet(fd int) bool { | ||
| idx, bit := index(fd) | ||
| return fs.X__fds_bits[idx]&bit != 0 | ||
| } | ||
| func (fs *FdSet) Set(fds ...int) { | ||
| for _, fd := range fds { | ||
| idx, bit := index(fd) | ||
| fs.X__fds_bits[idx] |= bit | ||
| } | ||
| } | ||
| func (fs *FdSet) Zero() { | ||
| *fs = FdSet{} | ||
| } |
| @@ -0,0 +1,13 @@ | ||
| // +build arm,freebsd 386,freebsd | ||
| // The type of FdSet.Bits is different on different platforms. | ||
| // This file is for FreeBSD where FdSet.Bits is actually X__fds_bits and it's []uint32. | ||
| package sys | ||
| const NFDBits = 32 | ||
| func index(fd int) (idx uint, bit uint32) { | ||
| u := uint(fd) | ||
| return u / NFDBits, 1 << (u % NFDBits) | ||
| } |
| @@ -0,0 +1,13 @@ | ||
| // +build amd64,freebsd arm64,freebsd | ||
| // The type of FdSet.Bits is different on different platforms. | ||
| // This file is for FreeBSD where FdSet.Bits is actually X__fds_bits and it's []uint64. | ||
| package sys | ||
| const NFDBits = 64 | ||
| func index(fd int) (idx uint, bit uint64) { | ||
| u := uint(fd) | ||
| return u / NFDBits, 1 << (u % NFDBits) | ||
| } |
0 comments on commit
7dd9aac