src/server/daemon/event_linux.c

changeset 543
3335f431a91b
parent 542
1327febf99c4
child 545
720893ec7d48
--- a/src/server/daemon/event_linux.c	Sun Aug 11 18:51:39 2024 +0200
+++ b/src/server/daemon/event_linux.c	Mon Aug 12 00:22:37 2024 +0200
@@ -94,14 +94,15 @@
     struct epoll_event events[EV_MAX_EVENTS];
     Event* finished[EV_MAX_EVENTS];
     
+    int loop_ctn = 0;
     for(;;) {
         /* wait for events */
-        int ret = epoll_wait(ep, events, 16, 100000);
+        int ret = epoll_wait(ep, events, 16, EV_IDLE_TIMEOUT * 1000);
         if(ret == -1 && errno != EINTR) {
             log_ereport(LOG_FAILURE, "epoll_wait failed: %s", strerror(errno));
             continue;
         }
-        
+              
         int numfinished = 0;
         ev->base.numret = 0;
         for(int i=0;i<ret;i++) {
@@ -183,6 +184,11 @@
             EVReturn ret = ev->base.fnreturn[i];
             nsapi_saf_return(ret.sn, ret.rq, ret.ret);
         }
+        
+        if(ret == 0 || ++loop_ctn >= EV_IDLE_LOOP_CTN) {
+            watchlist_check(&ev->base, 0);
+            loop_ctn = 0;
+        }
     }
 }
 
@@ -202,7 +208,7 @@
     event->object = (intptr_t)fd;
     event->events = EVENT_POLLIN;
     struct epoll_event epev;
-    epev.events = EPOLLIN | EPOLLET; // input event, edge triggered
+    epev.events = EPOLLIN | EPOLLRDHUP | EPOLLET; // input event, edge triggered
     epev.data.ptr = event;
     return epoll_ctl(ev->ep, EPOLL_CTL_ADD, fd, &epev);
 }
@@ -212,7 +218,7 @@
     event->object = (intptr_t)fd;
     event->events = EVENT_POLLOUT;
     struct epoll_event epev;
-    epev.events = EPOLLOUT | EPOLLET; // input event, edge triggered
+    epev.events = EPOLLOUT | EPOLLRDHUP | EPOLLET; // input event, edge triggered
     epev.data.ptr = event;
     return epoll_ctl(ev->ep, EPOLL_CTL_ADD, fd, &epev);
 }

mercurial