class INotify::Notifier
def readpartial(size)
def readpartial(size) # Use Ruby's readpartial if possible, to avoid blocking other threads. begin return to_io.readpartial(size) if self.class.supports_ruby_io? rescue Errno::EBADF, IOError # If the IO has already been closed, reading from it will cause # Errno::EBADF. In JRuby it can raise IOError with invalid or # closed file descriptor. return nil rescue IOError => ex return nil if ex.message =~ /stream closed/ raise end tries = 0 begin tries += 1 buffer = FFI::MemoryPointer.new(:char, size) size_read = Native.read(fd, buffer, size) return buffer.read_string(size_read) if size_read >= 0 end while FFI.errno == Errno::EINTR::Errno && tries <= 5 raise SystemCallError.new("Error reading inotify events" + case FFI.errno when Errno::EAGAIN::Errno; ": no data available for non-blocking I/O" when Errno::EBADF::Errno; ": invalid or closed file descriptor" when Errno::EFAULT::Errno; ": invalid buffer" when Errno::EINVAL::Errno; ": invalid file descriptor" when Errno::EIO::Errno; ": I/O error" when Errno::EISDIR::Errno; ": file descriptor is a directory" else; "" end, FFI.errno) end