From adf781d11645481a24264724e1d32e1eddb886f6 Mon Sep 17 00:00:00 2001
From: Martin Karlgren <marty@roxen.com>
Date: Thu, 15 Oct 2015 14:31:41 +0200
Subject: [PATCH] CFRunLoop: Set pdb->event_count correctly in noteEvents.

kevent returns the number of events placed in the eventlist. Previously,
pdb->event_count was always set to POLL_SET_SIZE, so previous events
could be picked up again by pdb_low_backend_once if the number of events
was lower than in the previous round.
---
 src/backend.cmod | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/backend.cmod b/src/backend.cmod
index db5430a801..e66d70af00 100644
--- a/src/backend.cmod
+++ b/src/backend.cmod
@@ -3522,13 +3522,18 @@ PIKECLASS PollDeviceBackend
     struct timespec tv;
     struct PollDeviceBackend_struct * this_backend;
     int fd;
+    int numevts;
 	
     tv.tv_sec = 0;
     tv.tv_nsec = 0;
     this_backend = (struct PollDeviceBackend_struct *)info;
     fd = CFFileDescriptorGetNativeDescriptor(fdref);
-    kevent(fd, NULL, 0, this_backend->poll_fds, POLL_SET_SIZE, &tv);
-    this_backend->event_count = POLL_SET_SIZE;
+    numevts = kevent(fd, NULL, 0, this_backend->poll_fds, POLL_SET_SIZE, &tv);
+    if (numevts >= 0)
+      this_backend->event_count = numevts;
+    else
+      Pike_error("kevent failure in noteEvents for fd %d (errno: %d).\n",
+                 fd, errno);
   }
 #endif /* BACKEND_USES_CFRUNLOOP */
 
-- 
GitLab