Inotify works when it is an array. Experimentally was found that 16 events is enough.
This commit is contained in:
parent
bf0595453c
commit
338b153aa1
@ -9,6 +9,8 @@ import (
|
||||
|
||||
const CrDelMask uint32 = syscall.IN_CREATE | syscall.IN_DELETE
|
||||
|
||||
const inotifyCount = 16
|
||||
|
||||
type FSWatcher struct {
|
||||
fd int
|
||||
wds []int
|
||||
@ -41,9 +43,9 @@ func (fsw *FSWatcher) AddWatch(path string, mask uint32) error {
|
||||
|
||||
// WatchForMask checking for events from mask and returns inotify mask to channel.
|
||||
func (fsw *FSWatcher) WatchForMask(fired chan uint32, mask uint32) {
|
||||
buffer := make([]byte, syscall.SizeofInotifyEvent)
|
||||
go func() {
|
||||
for !fsw.closed {
|
||||
buffer := make([]byte, syscall.SizeofInotifyEvent*inotifyCount)
|
||||
n, err := syscall.Read(fsw.fd, buffer)
|
||||
if err != nil {
|
||||
break
|
||||
@ -53,9 +55,11 @@ func (fsw *FSWatcher) WatchForMask(fired chan uint32, mask uint32) {
|
||||
continue
|
||||
}
|
||||
|
||||
event := (*syscall.InotifyEvent)(unsafe.Pointer(&buffer[0]))
|
||||
if event.Mask&mask > 0 {
|
||||
fired <- event.Mask
|
||||
for offset := 0; offset < len(buffer); offset += syscall.SizeofInotifyEvent {
|
||||
event := (*syscall.InotifyEvent)(unsafe.Pointer(&buffer[offset]))
|
||||
if event.Mask&mask > 0 {
|
||||
fired <- event.Mask
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
Loading…
Reference in New Issue
Block a user