Skip to content

Commit

Permalink
Handled distinctive NFDBits and func index's return values according to
Browse files Browse the repository at this point in the history
different architectures.

Signed-off-by: xchenan <xchenan@gmail.com>
  • Loading branch information
xchenan committed May 23, 2017
1 parent 519b7e5 commit 0b87620
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
4 changes: 1 addition & 3 deletions sys/select.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package sys

import (
"syscall"
)
import "syscall"

type FdSet syscall.FdSet

Expand Down
15 changes: 15 additions & 0 deletions sys/select_32.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// +build darwin 386,freebsd arm,freebsd 386,linux arm,linux netbsd openbsd

// Differnt architectures lead to different bits of uint
// and different types of FdSet.Bits[].
// Hence, NFDBits and types of func index's return values
// have to be specified from case to case.

package sys

const NFDBits = 32

func index(fd int) (idx uint, bit int32) {
u := uint(fd)
return u / NFDBits, 1 << (u % NFDBits)
}
15 changes: 15 additions & 0 deletions sys/select_64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// +build amd64,dragonfly amd64,freebsd amd64,linux arm64,linux

// Differnt architectures lead to different bits of uint
// and different types of FdSet.Bits[].
// Hence, NFDBits and types of func index's return values
// have to be specified from case to case.

package sys

const NFDBits = 64

func index(fd int) (idx uint, bit int64) {
u := uint(fd)
return u / NFDBits, 1 << (u % NFDBits)
}
7 changes: 0 additions & 7 deletions sys/select_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ package sys

import "syscall"

const NFDBits = 32

func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *syscall.Timeval) (err error) {
return syscall.Select(nfd, r.s(), w.s(), e.s(), timeout)
}

func index(fd int) (idx uint, bit int32) {
u := uint(fd)
return u / NFDBits, 1 << (u % NFDBits)
}
7 changes: 0 additions & 7 deletions sys/select_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@ package sys

import "syscall"

const NFDBits = 64

func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *syscall.Timeval) error {
_, err := syscall.Select(nfd, r.s(), w.s(), e.s(), timeout)
return err
}

func index(fd int) (idx uint, bit int64) {
u := uint(fd)
return u / NFDBits, 1 << (u % NFDBits)
}

0 comments on commit 0b87620

Please sign in to comment.