fix kqueue event deletion webdav

Thu, 03 Dec 2020 13:25:26 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 03 Dec 2020 13:25:26 +0100
branch
webdav
changeset 266
783467806e2d
parent 265
59f99038a576
child 267
4ded424f4a5f

fix kqueue event deletion

src/server/daemon/event_bsd.c file | annotate | diff | comparison | revisions
--- a/src/server/daemon/event_bsd.c	Thu Dec 03 12:38:46 2020 +0100
+++ b/src/server/daemon/event_bsd.c	Thu Dec 03 13:25:26 2020 +0100
@@ -74,7 +74,6 @@
         // wait for events
         int nev = kevent(ev->kqueue, changes, numchanges, events, 64, &timeout);  
         if(nev == -1) {
-            // TODO: check for error
             log_ereport(LOG_FAILURE, "kevent: %s", strerror(errno));
             continue;
         }
@@ -83,7 +82,14 @@
         for(int i=0;i<nev;i++) {
             Event *event = (Event*)events[i].udata;
             if(!event) {
-                log_ereport(LOG_WARN, "Unknown kevent (ident=%d)", (int)events[i].ident);
+                if(events[i].flags == 0) {
+                    log_ereport(LOG_WARN, "Unknown kevent (ident=%d)", (int)events[i].ident);
+                }
+                // don't warn in case flags is not 0, because socket EOF events
+                // are triggered even if we apply EV_DELETE in the changelist
+                // the only way to stop this is to apply the changelist without
+                // getting new events, but that comes with a performance penalty
+                
                 continue;
             }
             
@@ -104,12 +110,22 @@
                     int e = event->events;
                     int e_fd = events[i].ident;
                     if((e & EVENT_POLLIN) != (saved_ev & EVENT_POLLIN)) {
-                        int f = (e & EVENT_POLLIN) == EVENT_POLLIN ? EV_ADD : EV_DELETE;
-                        EV_SET(&changes[numchanges++], e_fd, EVFILT_READ, f, 0, 0, event);
+                        if((e & EVENT_POLLIN) == EVENT_POLLIN) {
+                            // add
+                            EV_SET(&changes[numchanges++], e_fd, EVFILT_READ, EV_ADD, 0, 0, event);
+                        } else {
+                            // delete
+                            EV_SET(&changes[numchanges++], e_fd, EVFILT_READ, EV_DELETE, 0, 0, NULL);
+                        }
                     }
                     if((e & EVENT_POLLOUT) != (saved_ev & EVENT_POLLOUT)) {
-                        int f = (e & EVENT_POLLOUT) == EVENT_POLLOUT ? EV_ADD : EV_DELETE;
-                        EV_SET(&changes[numchanges++], e_fd, EVFILT_WRITE, f, 0, 0, event);
+                        if((e & EVENT_POLLOUT) == EVENT_POLLOUT) {
+                            // add
+                            EV_SET(&changes[numchanges++], e_fd, EVFILT_WRITE, EV_ADD, 0, 0, event);
+                        } else {
+                            // delete
+                            EV_SET(&changes[numchanges++], e_fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
+                        }
                     }
                 }
             }
@@ -117,17 +133,6 @@
     }
 }
 
-int ev_convert2sys_events(int events) {
-    int e = 0;
-    if((events & EVENT_POLLIN) == EVENT_POLLIN) {
-        e |= EVFILT_READ;
-    }
-    if((events & EVENT_POLLOUT) == EVENT_POLLOUT) {
-        e |= EVFILT_WRITE;
-    }
-    return e;
-}
-
 int ev_pollin(EventHandler *h, int fd, Event *event) {
     event->events = EVENT_POLLIN;
     struct kevent kev;

mercurial