Permalink
Browse files

Fix FreeBSD build (#382)

FdSet.Bits is very weird here for some reason
  • Loading branch information...
myfreeweb authored and xiaq committed Jul 4, 2017
1 parent 1b7dc43 commit 7dd9aacecf927c5a00918f986f7d6abff84f6fe0
Showing with 72 additions and 2 deletions.
  1. +2 −0 sys/select.go
  2. +1 −1 sys/select_32.go
  3. +1 −1 sys/select_64.go
  4. +42 −0 sys/select_freebsd.go
  5. +13 −0 sys/select_freebsd_32.go
  6. +13 −0 sys/select_freebsd_64.go
View
@@ -1,3 +1,5 @@
// +build !freebsd
package sys
import "syscall"
View
@@ -1,4 +1,4 @@
// +build darwin 386,freebsd arm,freebsd 386,linux arm,linux netbsd openbsd
// +build darwin 386,linux arm,linux netbsd openbsd
// The type of FdSet.Bits is different on different platforms.
// This file is for those where FdSet.Bits is []int32.
View
@@ -1,4 +1,4 @@
// +build amd64,dragonfly amd64,freebsd amd64,linux arm64,linux
// +build amd64,dragonfly amd64,linux arm64,linux
// The type of FdSet.Bits is different on different platforms.
// This file is for those where FdSet.Bits is []int64.
View
@@ -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{}
}
View
@@ -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)
}
View
@@ -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

Please sign in to comment.