]> jfr.im git - irc/evilnet/x3.git/blobdiff - src/ioset-kevent.c
Couple of srvx updates.
[irc/evilnet/x3.git] / src / ioset-kevent.c
index 5d6f0bbb10463c36634cdbfdb3e455a057986f95..459e487d5f62c3651a0c7677423c7b7029ebcd7f 100644 (file)
@@ -5,7 +5,7 @@
  *
  * srvx is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
@@ -46,7 +46,9 @@ ioset_kevent_add(struct io_fd *fd)
     int res;
 
     EV_SET(&changes[nchanges++], fd->fd, EVFILT_READ, EV_ADD, 0, 0, fd);
-    EV_SET(&changes[nchanges++], fd->fd, EVFILT_WRITE, fd_wants_writes(fd) ? EV_ADD : EV_DELETE, 0, 0, fd);
+    if (fd_wants_writes(fd)) {
+       EV_SET(&changes[nchanges++], fd->fd, EVFILT_WRITE, EV_ADD, 0, 0, fd);
+    }
     res = kevent(kq_fd, changes, nchanges, NULL, 0, NULL);
     if (res < 0) {
        log_module(MAIN_LOG, LOG_ERROR, "kevent() add failed: %s", strerror(errno));
@@ -73,7 +75,16 @@ ioset_kevent_remove(struct io_fd *fd, int closed)
 static void
 ioset_kevent_update(struct io_fd *fd)
 {
-    ioset_kevent_add(fd);
+    struct kevent changes[2];
+    int nchanges = 0;
+    int res;
+
+    EV_SET(&changes[nchanges++], fd->fd, EVFILT_READ, EV_ADD, 0, 0, fd);
+    EV_SET(&changes[nchanges++], fd->fd, EVFILT_WRITE, fd_wants_writes(fd) ? EV_ADD : EV_DELETE, 0, 0, fd);
+    res = kevent(kq_fd, changes, nchanges, NULL, 0, NULL);
+    if (res < 0) {
+       log_module(MAIN_LOG, LOG_ERROR, "kevent() add failed: %s", strerror(errno));
+    }
 }
 
 static void
@@ -102,7 +113,7 @@ ioset_kevent_loop(struct timeval *timeout)
        pts = NULL;
     }
     res = kevent(kq_fd, NULL, 0, events, MAX_EVENTS, pts);
-    if (res < 0) {
+    if ((res < 0) && (errno != EINTR)) {
        log_module(MAIN_LOG, LOG_ERROR, "kevent() poll failed: %s", strerror(errno));
        return 1;
     }