X-Git-Url: https://git.llucax.com/software/libev.git/blobdiff_plain/4d842bfffe9d21022fb0e6ea51d3a5eedb39e69e..ed54de67c9823483cc94f0decfd2f5405a5844f7:/event.c diff --git a/event.c b/event.c index b24d702..1d30ce5 100644 --- a/event.c +++ b/event.c @@ -160,13 +160,8 @@ x_cb_io (EV_P_ struct ev_io *w, int revents) { struct event *ev = (struct event *)(((char *)w) - offsetof (struct event, iosig.io)); - if (revents & EV_ERROR) + if ((revents & EV_ERROR) || !(ev->ev_events & EV_PERSIST)) event_del (ev); - else if (!(ev->ev_events & EV_PERSIST) && ev_is_active (w)) - { - ev_io_stop (EV_A_ w); - ev->ev_flags &= ~EVLIST_INSERTED; - } x_cb (ev, revents); } @@ -209,31 +204,38 @@ int event_add (struct event *ev, struct timeval *tv) { dLOOPev; - /* disable all watchers */ - event_del (ev); - if (ev->ev_events & EV_SIGNAL) { - ev_signal_set (&ev->iosig.sig, ev->ev_fd); - ev_signal_start (EV_A_ &ev->iosig.sig); + if (!ev_is_active (&ev->iosig.sig)) + { + ev_signal_set (&ev->iosig.sig, ev->ev_fd); + ev_signal_start (EV_A_ &ev->iosig.sig); - ev->ev_flags |= EVLIST_SIGNAL; + ev->ev_flags |= EVLIST_SIGNAL; + } } else if (ev->ev_events & (EV_READ | EV_WRITE)) { - ev_io_set (&ev->iosig.io, ev->ev_fd, ev->ev_events & (EV_READ | EV_WRITE)); - ev_io_start (EV_A_ &ev->iosig.io); + if (!ev_is_active (&ev->iosig.io)) + { + ev_io_set (&ev->iosig.io, ev->ev_fd, ev->ev_events & (EV_READ | EV_WRITE)); + ev_io_start (EV_A_ &ev->iosig.io); - ev->ev_flags |= EVLIST_INSERTED; + ev->ev_flags |= EVLIST_INSERTED; + } } if (tv) { - ev_timer_set (&ev->to, tv_get (tv), 0.); - ev_timer_start (EV_A_ &ev->to); - + ev->to.repeat = tv_get (tv); + ev_timer_again (EV_A_ &ev->to); ev->ev_flags |= EVLIST_TIMEOUT; } + else + { + ev_timer_stop (EV_A_ &ev->to); + ev->ev_flags &= ~EVLIST_TIMEOUT; + } ev->ev_flags |= EVLIST_ACTIVE; @@ -245,17 +247,9 @@ int event_del (struct event *ev) dLOOPev; if (ev->ev_events & EV_SIGNAL) - { - /* sig */ - if (ev_is_active (&ev->iosig.sig)) - ev_signal_stop (EV_A_ &ev->iosig.sig); - } + ev_signal_stop (EV_A_ &ev->iosig.sig); else if (ev->ev_events & (EV_READ | EV_WRITE)) - { - /* io */ - if (ev_is_active (&ev->iosig.io)) - ev_io_stop (EV_A_ &ev->iosig.io); - } + ev_io_stop (EV_A_ &ev->iosig.io); if (ev_is_active (&ev->to)) ev_timer_stop (EV_A_ &ev->to); @@ -347,7 +341,7 @@ x_loopexit_cb (int revents, void *base) { dLOOPbase; - ev_unloop (EV_A_ EVUNLOOP_ONCE); + ev_unloop (EV_A_ EVUNLOOP_ONE); } int event_base_loopexit (struct event_base *base, struct timeval *tv)