src/server/daemon/event_solaris.c

changeset 547
280bf87c8689
parent 541
1e1fca11aaff
child 552
4ed0e46aa9dc
--- a/src/server/daemon/event_solaris.c	Tue Aug 13 20:08:13 2024 +0200
+++ b/src/server/daemon/event_solaris.c	Thu Aug 15 21:46:57 2024 +0200
@@ -64,6 +64,20 @@
     return ev;
 }
 
+static volatile int ev_close = 0;
+
+void ev_instance_close(EventHandler *h) {
+    EventHandlerSolaris *ev = (EventHandlerSolaris*)h;
+    close(ev->port);
+    ev_close = 1;
+}
+
+// unique event addr that indicates shutdown
+static Event shutdown_event;
+void ev_instance_shutdown(EventHandler *h) {
+    event_send(h, &shutdown_event);
+}
+
 
 void ev_handle_events(EventHandlerSolaris *ev) {
     EventHandler *h = (EventHandler*)ev;
@@ -78,8 +92,12 @@
         uint_t nev = 1;
         int ret = port_getn(ev->port, events, EV_MAX_EVENTS, &nev, &timeout);
         if(ret == -1) {
-            // TODO: check for error
-            perror("port_getn");
+            if(errno != EINTR && errno != ETIME) {
+                if(!ev_close) {
+                    log_ereport(LOG_CATASTROPHE, "port_getn failed: %s", strerror(errno));
+                }
+                break;
+            }
             continue;
         }
         
@@ -120,6 +138,8 @@
                     } else if(event->finish) {
                         event->finish(h, event);
                     }
+                } else if(event == &shutdown_event) {
+                    ev_instance_close(h);
                 }
             }  
         }
@@ -137,6 +157,8 @@
             nsapi_saf_return(ret.sn, ret.rq, ret.ret);
         }
     }
+    
+    free(ev);
 }
 
 int ev_convert2sys_events(int events) {

mercurial