Import new eloop.
authorRoy Marples <roy@marples.name>
Thu, 14 May 2015 21:47:18 +0000 (21:47 +0000)
committerRoy Marples <roy@marples.name>
Thu, 14 May 2015 21:47:18 +0000 (21:47 +0000)
src/dhcpcd-curses/dhcpcd-curses.c
src/dhcpcd-curses/eloop.c
src/dhcpcd-curses/eloop.h

index df6b2f12459ec6e9227d67d4d8c813aa17de344f..102d6ef2f9bb7529788cbc263ea42db821b10d66 100644 (file)
@@ -243,7 +243,7 @@ status_cb(DHCPCD_CONNECTION *con,
                int fd;
 
                fd = dhcpcd_get_fd(ctx->con);
-               eloop_event_delete(ctx->eloop, fd, 0);
+               eloop_event_delete(ctx->eloop, fd);
                ctx->online = ctx->carrier = false;
                eloop_timeout_delete(ctx->eloop, NULL, ctx);
                set_summary(ctx, NULL);
@@ -406,7 +406,7 @@ wpa_status_cb(DHCPCD_WPA *wpa,
                int fd;
 
                fd = dhcpcd_wpa_get_fd(wpa);
-               eloop_event_delete(ctx->eloop, fd, 0);
+               eloop_event_delete(ctx->eloop, fd);
                dhcpcd_wpa_close(wpa);
                TAILQ_FOREACH_SAFE(w, &ctx->wi_scans, next, wn) {
                        if (w->interface == i) {
index 458dd29e4a9ad2f5e179b21020ca2fadd52745bd..bac2e7df1c0833fcbaffd39ae8a0d63a3e215f1a 100644 (file)
@@ -221,8 +221,10 @@ eloop_event_add(struct eloop *eloop, int fd,
        e->write_cb_arg = write_cb_arg;
 
 #if defined(HAVE_KQUEUE)
-       EV_SET(&ke[0], (uintptr_t)fd, EVFILT_READ, EV_ADD, 0, 0, UPTR(e));
-       if (write_cb)
+       if (read_cb != NULL)
+               EV_SET(&ke[0], (uintptr_t)fd, EVFILT_READ,
+                   EV_ADD, 0, 0, UPTR(e));
+       if (write_cb != NULL)
                EV_SET(&ke[1], (uintptr_t)fd, EVFILT_WRITE,
                    EV_ADD, 0, 0, UPTR(e));
        if (kevent(eloop->poll_fd, ke, write_cb ? 2 : 1, NULL, 0, NULL) == -1)
@@ -252,7 +254,7 @@ err:
 }
 
 void
-eloop_event_delete(struct eloop *eloop, int fd, int write_only)
+eloop_event_delete_write(struct eloop *eloop, int fd, int write_only)
 {
        struct eloop_event *e;
 #if defined(HAVE_KQUEUE)
@@ -265,8 +267,8 @@ eloop_event_delete(struct eloop *eloop, int fd, int write_only)
 
        TAILQ_FOREACH(e, &eloop->events, next) {
                if (e->fd == fd) {
-                       if (write_only) {
-                               if (e->write_cb) {
+                       if (write_only && e->read_cb != NULL) {
+                               if (e->write_cb != NULL) {
                                        e->write_cb = NULL;
                                        e->write_cb_arg = NULL;
 #if defined(HAVE_KQUEUE)
@@ -284,7 +286,6 @@ eloop_event_delete(struct eloop *eloop, int fd, int write_only)
                                            EPOLL_CTL_MOD, fd, &epe);
 #endif
                                }
-
                        } else {
                                TAILQ_REMOVE(&eloop->events, e, next);
 #if defined(HAVE_KQUEUE)
@@ -762,12 +763,13 @@ eloop_start(struct eloop *eloop, sigset_t *signals)
 #elif defined(HAVE_EPOLL)
                if (n) {
                        e = (struct eloop_event *)epe.data.ptr;
-                       if (epe.events & EPOLLOUT && e->write_cb) {
+                       if (epe.events & EPOLLOUT && e->write_cb != NULL) {
                                e->write_cb(e->write_cb_arg);
                                continue;
                        }
                        if (epe.events &
-                           (EPOLLIN | EPOLLERR | EPOLLHUP))
+                           (EPOLLIN | EPOLLERR | EPOLLHUP) &&
+                           e->read_cb != NULL)
                        {
                                e->read_cb(e->read_cb_arg);
                                continue;
@@ -777,12 +779,12 @@ eloop_start(struct eloop *eloop, sigset_t *signals)
                if (n > 0) {
                        TAILQ_FOREACH(e, &eloop->events, next) {
                                if (e->pollfd->revents & POLLOUT &&
-                                   e->write_cb)
+                                   e->write_cb != NULL)
                                {
                                        e->write_cb(e->write_cb_arg);
                                        break;
                                }
-                               if (e->pollfd->revents) {
+                               if (e->pollfd->revents && e->read_cb != NULL) {
                                        e->read_cb(e->read_cb_arg);
                                        break;
                                }
index 6746aaff14585affb522e8a48c652245daee7a39..c5211a7562beec223bc902f098e6fe43f348c673 100644 (file)
@@ -152,7 +152,11 @@ struct eloop {
 int eloop_event_add(struct eloop *, int,
     void (*)(void *), void *,
     void (*)(void *), void *);
-void eloop_event_delete(struct eloop *, int, int);
+#define eloop_event_delete(eloop, fd) \
+    eloop_event_delete_write((eloop), (fd), 0)
+#define eloop_event_remove_writecb(eloop, fd) \
+    eloop_event_delete_write((eloop), (fd), 1)
+void eloop_event_delete_write(struct eloop *, int, int);
 
 #define eloop_timeout_add_tv(eloop, tv, cb, ctx) \
     eloop_q_timeout_add_tv((eloop), ELOOP_QUEUE, (tv), (cb), (ctx))
@@ -162,11 +166,11 @@ void eloop_event_delete(struct eloop *, int, int);
     eloop_q_timeout_add_msec((eloop), ELOOP_QUEUE, (ms), (cb), (ctx))
 #define eloop_timeout_delete(eloop, cb, ctx) \
     eloop_q_timeout_delete((eloop), ELOOP_QUEUE, (cb), (ctx))
-int eloop_q_timeout_add_tv(struct eloop *, int queue,
+int eloop_q_timeout_add_tv(struct eloop *, int,
     const struct timespec *, void (*)(void *), void *);
-int eloop_q_timeout_add_sec(struct eloop *, int queue,
+int eloop_q_timeout_add_sec(struct eloop *, int,
     time_t, void (*)(void *), void *);
-int eloop_q_timeout_add_msec(struct eloop *, int queue,
+int eloop_q_timeout_add_msec(struct eloop *, int,
     long, void (*)(void *), void *);
 void eloop_q_timeout_delete(struct eloop *, int, void (*)(void *), void *);