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 CrDelMask uint32 = syscall.IN_CREATE | syscall.IN_DELETE
const inotifyCount = 16
type FSWatcher struct { type FSWatcher struct {
fd int fd int
wds []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. // WatchForMask checking for events from mask and returns inotify mask to channel.
func (fsw *FSWatcher) WatchForMask(fired chan uint32, mask uint32) { func (fsw *FSWatcher) WatchForMask(fired chan uint32, mask uint32) {
buffer := make([]byte, syscall.SizeofInotifyEvent)
go func() { go func() {
for !fsw.closed { for !fsw.closed {
buffer := make([]byte, syscall.SizeofInotifyEvent*inotifyCount)
n, err := syscall.Read(fsw.fd, buffer) n, err := syscall.Read(fsw.fd, buffer)
if err != nil { if err != nil {
break break
@ -53,9 +55,11 @@ func (fsw *FSWatcher) WatchForMask(fired chan uint32, mask uint32) {
continue continue
} }
event := (*syscall.InotifyEvent)(unsafe.Pointer(&buffer[0])) for offset := 0; offset < len(buffer); offset += syscall.SizeofInotifyEvent {
if event.Mask&mask > 0 { event := (*syscall.InotifyEvent)(unsafe.Pointer(&buffer[offset]))
fired <- event.Mask if event.Mask&mask > 0 {
fired <- event.Mask
}
} }
} }
}() }()