[iolib-devel] Patch for a nil callback invocation.

Peter Keller psilord at cs.wisc.edu
Wed Jan 20 06:33:26 UTC 2010


Hello,

Under the conditions where there are two or more handlers registered for a
single fd in the multiplexer and one of the handlers removes all the fd's
callbacks and other callbacks for that fd should have been invoked in the
same event-dispath iteration, there is an invocation of a nil callback
in event-dispatch. To the best of my knowledge, this patch below fixes it.

Thank you.

-pete


diff --git a/src/multiplex/event-loop.lisp b/src/multiplex/event-loop.lisp
index 35879fd..4afba32 100644
--- a/src/multiplex/event-loop.lisp
+++ b/src/multiplex/event-loop.lisp
@@ -306,7 +306,8 @@ within the extent of BODY.  Closes VAR."
         (setf expired-events nil)
         (setf (values eventsp deletion-list)
               (dispatch-fd-events-once event-base poll-timeout now))
-        (%remove-handlers event-base deletion-list)
+        (unless (equal '(nil nil) deletion-list)
+                (%remove-handlers event-base deletion-list))
         (when (expire-pending-timers fd-timers now) (setf eventsp t))
         (dispatch-fd-timeouts expired-events)
         (when (expire-pending-timers timers now) (setf eventsp t))
@@ -352,13 +353,14 @@ within the extent of BODY.  Closes VAR."
 
 (defun %dispatch-event (fd-entry event-type errorp now)
   (let ((ev (fd-entry-handler fd-entry event-type)))
-    (funcall (fd-handler-callback ev)
-             (fd-entry-fd fd-entry)
-             event-type
-             (if errorp :error nil))
-    (when-let (timer (fd-handler-timer ev))
-      (reschedule-timer-relative-to-now timer now))
-    (fd-handler-one-shot-p ev)))
+    (when ev
+          (funcall (fd-handler-callback ev)
+                   (fd-entry-fd fd-entry)
+                   event-type
+                   (if errorp :error nil))
+          (when-let (timer (fd-handler-timer ev))
+                    (reschedule-timer-relative-to-now timer now))
+          (fd-handler-one-shot-p ev))))
 
 (defun dispatch-fd-timeouts (events)
   (dolist (ev events)





More information about the iolib-devel mailing list