Skip to content

Commit

Permalink
Fix waitForFrame function
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksandr Senkovych committed Jul 2, 2016
1 parent 1124c17 commit dba29cd
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions v4l2.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,16 @@ func startStreaming(fd uintptr) (err error) {

}

func FD_SET(p *unix.FdSet, i int) {
var l int = int(len(p.Bits))
p.Bits[i/l] |= 1 << uintptr(i%l)
}

func waitForFrame(fd uintptr, timeout uint32) (count int, err error) {

for {
fds := &unix.FdSet{}
fdmask := uint(1) << (uint32(fd) % uint32(FD_BITS))
fds.Bits[fd/FD_BITS] |= int64(fdmask)
FD_SET(fds, int(fd))

var oneSecInNsec int64 = 1e9
timeoutNsec := int64(timeout) * oneSecInNsec
Expand All @@ -375,7 +379,9 @@ func waitForFrame(fd uintptr, timeout uint32) (count int, err error) {
if count < 0 && err == unix.EINTR {
continue
}
return
}

}

func getNativeByteOrder() binary.ByteOrder {
Expand All @@ -400,8 +406,3 @@ func CToGoString(c []byte) string {
}
return string(c[:n+1])
}

const (
FD_BITS = uintptr(unsafe.Sizeof(0) * 8)
FD_SETSIZE = 1024
)

0 comments on commit dba29cd

Please sign in to comment.