Skip to content
Browse files

Add a time-out argument for read-events.

  • Loading branch information...
1 parent cb4e78f commit 543734d75b24e717eea786f1e1f113267cd3ca40 @stassats committed Jul 19, 2013
Showing with 32 additions and 15 deletions.
  1. +18 −2 README
  2. +14 −13 inotify.lisp
View
20 README
@@ -1,5 +1,3 @@
-Example:
-
(with-inotify (inot `((,(user-homedir-pathname) ,in-create)))
(read-events inot))
@@ -14,3 +12,21 @@ blocks
:COOKIE 0
:NAME "file"))
+With a timeout:
+
+(inotify:with-inotify (inotify `(("/tmp/test" ,inotify:in-modify)))
+ (loop for events = (inotify:read-events inotify :time-out 1)
+ thereis events
+ do (write-line "timed out")))
+timed out
+timed out
+timed out
+
+$ echo 10 >> /tmp/test
+
+ =>
+(#S(INOTIFY:EVENT
+ :WATCH #<INOTIFY:WATCH pathname: #P"/tmp/test" mask: 2>
+ :MASK 2
+ :COOKIE 0
+ :NAME NIL))
View
27 inotify.lisp
@@ -133,19 +133,20 @@
(values event
(+ +event-size+ name-length)))))
-(defun read-events (inotify)
- (let* ((buffer (inotify-buffer inotify))
- (bytes-read
- (isys:repeat-upon-eintr
- (isys:read (inotify-fd inotify)
- buffer
- (inotify-buffer-size inotify)))))
- (loop with event and event-length
- for offset = 0 then (+ offset event-length)
- while (< offset bytes-read)
- do (setf (values event event-length)
- (read-event inotify (inc-pointer buffer offset)))
- collect event)))
+(defun read-events (inotify &key time-out)
+ (when (iomux:wait-until-fd-ready (inotify-fd inotify) :input time-out)
+ (let* ((buffer (inotify-buffer inotify))
+ (bytes-read
+ (isys:repeat-upon-eintr
+ (isys:read (inotify-fd inotify)
+ buffer
+ (inotify-buffer-size inotify)))))
+ (loop with event and event-length
+ for offset = 0 then (+ offset event-length)
+ while (< offset bytes-read)
+ do (setf (values event event-length)
+ (read-event inotify (inc-pointer buffer offset)))
+ collect event))))
(defun make-inotify-with-watches (paths-with-masks)
(let ((inotify (make-inotify)))

0 comments on commit 543734d

Please sign in to comment.
Something went wrong with that request. Please try again.