diff --git a/src/linuxapi/inotify.py b/src/linuxapi/inotify.py index 1fc7704..485837b 100644 --- a/src/linuxapi/inotify.py +++ b/src/linuxapi/inotify.py @@ -173,16 +173,21 @@ class Inotify(object): buf = memoryview(os.read(self.__fd, self.BUFSIZE)) nread = len(buf) - i = 0 + i = begin = 0 + end = self.STRUCT_SIZE while i < nread: - wd, mask, cookie, sz = self._unpack(buf) - end = self.STRUCT_SIZE - while end < nread and buf[end:end + 1] != b'\x00': - end += 1 - name = buf[self.STRUCT_SIZE:end].tobytes() + wd, mask, cookie, sz = self._unpack(buf[begin:end]) + begin = end + end += sz + x = begin + while buf[x:x + 1] != b'\x00': + x += 1 + name = buf[begin:x].tobytes() pathname = self.__watches[wd] - i += self.STRUCT_SIZE + sz + i += end yield Event(wd, mask, cookie, name, pathname) + begin = end + end += self.STRUCT_SIZE def close(self): '''Close all watch descriptors and the inotify descriptor'''