try some more tsting

This commit is contained in:
Dominic Breuker
2018-02-26 07:41:28 +01:00
parent dd123848f2
commit 6c79b80623
17 changed files with 262 additions and 28 deletions

View File

@@ -0,0 +1,24 @@
package fswatcher
import (
"fmt"
"github.com/dominicbreuker/pspy/internal/fswatcher/inotify"
"golang.org/x/sys/unix"
)
func Observe(i *inotify.Inotify, triggerCh chan struct{}, dataCh chan []byte, errCh chan error) {
buf := make([]byte, 5*unix.SizeofInotifyEvent)
for {
n, errno := unix.Read(i.FD, buf)
if n == -1 {
errCh <- fmt.Errorf("reading from inotify fd: errno: %d", errno)
return
}
triggerCh <- struct{}{}
bufCopy := make([]byte, n)
copy(bufCopy, buf)
dataCh <- bufCopy
}
}