1
0

Inotify works when it is an array. Experimentally was found that 16 events is enough.

This commit is contained in:
Alexander Andreev 2022-02-08 02:13:15 +04:00
parent bf0595453c
commit 338b153aa1
Signed by: Arav
GPG Key ID: 1327FE8A374CC86F

View File

@ -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
}
}
}
}()