diff options
-rw-r--r-- | ev.c | 4 | ||||
-rw-r--r-- | ev.h | 1 | ||||
-rw-r--r-- | ev_epoll.c | 3 | ||||
-rw-r--r-- | evdns.c | 2 | ||||
-rw-r--r-- | event.c | 27 | ||||
-rw-r--r-- | event.h | 4 |
6 files changed, 22 insertions, 19 deletions
@@ -796,6 +796,8 @@ timers_reify (EV_P) { struct ev_timer *w = timers [0]; + assert (("inactive timer on timer heap detected", ev_is_active (w))); + /* first reschedule or stop timer */ if (w->repeat) { @@ -817,6 +819,8 @@ periodics_reify (EV_P) { struct ev_periodic *w = periodics [0]; + assert (("inactive timer on periodic heap detected", ev_is_active (w))); + /* first reschedule or stop timer */ if (w->interval) { @@ -283,6 +283,7 @@ void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revent #define ev_check_init(ev,cb) do { ev_watcher_init ((ev), (cb)); ev_check_set ((ev)); } while (0) #define ev_child_init(ev,cb,pid) do { ev_watcher_init ((ev), (cb)); ev_child_set ((ev),(pid)); } while (0) +#define ev_is_pending(ev) (0 + (ev)->pending) /* true when watcher is waiting for callback invocation */ #define ev_is_active(ev) (0 + (ev)->active) /* true when the watcher has been started */ #define ev_set_priority(ev,pri) (ev)->priority = pri @@ -42,7 +42,8 @@ epoll_modify (EV_P_ int fd, int oev, int nev) (nev & EV_READ ? EPOLLIN : 0) | (nev & EV_WRITE ? EPOLLOUT : 0); - epoll_ctl (epoll_fd, mode, fd, &ev); + if (!epoll_ctl (epoll_fd, mode, fd, &ev)) + fd_kill (EV_A_ fd); } static void @@ -1,4 +1,4 @@ -/* $Id: evdns.c,v 1.10 2007-11-04 18:29:44 root Exp $ */ +/* $Id: evdns.c,v 1.11 2007-11-04 19:45:09 root Exp $ */ /* The original version of this module was written by Adam Langley; for * a history of modifications, check out the subversion logs. @@ -158,22 +158,21 @@ x_cb_io (EV_P_ struct ev_io *w, int revents) static void x_cb_to (EV_P_ struct ev_timer *w, int revents) { - x_cb ((struct event *)(((char *)w) - offsetof (struct event, to)), revents); + struct event *ev = (struct event *)(((char *)w) - offsetof (struct event, to)); + + event_del (ev); + + x_cb (ev, revents); } void event_set (struct event *ev, int fd, short events, void (*cb)(int, short, void *), void *arg) { - if (!ev->initialised) - { - ev->initialised = 1; - - if (events & EV_SIGNAL) - ev_watcher_init (&ev->iosig.sig, x_cb_sig); - else - ev_watcher_init (&ev->iosig.io, x_cb_io); + if (events & EV_SIGNAL) + ev_watcher_init (&ev->iosig.sig, x_cb_sig); + else + ev_watcher_init (&ev->iosig.io, x_cb_io); - ev_watcher_init (&ev->to, x_cb_to); - } + ev_watcher_init (&ev->to, x_cb_to); ev->ev_base = x_cur; /* not threadsafe, but its like libevent works */ ev->ev_fd = fd; @@ -248,17 +247,17 @@ int event_pending (struct event *ev, short events, struct timeval *tv) if (ev->ev_events & EV_SIGNAL) { /* sig */ - if (ev->iosig.sig.pending) + if (ev_is_active (&ev->iosig.sig) || ev_is_pending (&ev->iosig.sig)) revents |= EV_SIGNAL; } else { /* io */ - if (ev->iosig.io.pending) + if (ev_is_active (&ev->iosig.io) || ev_is_pending (&ev->iosig.io)) revents |= ev->ev_events & (EV_READ | EV_WRITE); } - if (ev->to.pending) + if (ev->ev_events & EV_TIMEOUT || ev_is_active (&ev->to) || ev_is_pending (&ev->to)) { revents |= EV_TIMEOUT; @@ -54,8 +54,6 @@ struct event int ev_pri; int ev_res; short ev_events; - - char initialised; /* flag to work around some idiosynchrasies in the API */ }; #define EV_PERSIST 0x10 @@ -63,7 +61,7 @@ struct event #define EVENT_SIGNAL(ev) ((int) (ev)->ev_fd) #define EVENT_FD(ev) ((int) (ev)->ev_fd) -#define event_initialized(ev) ((ev)->initialised) +#define event_initialized(ev) 1 #define evtimer_add(ev,tv) event_add (ev, tv) #define evtimer_set(ev,cb,data) event_set (ev, -1, 0, cb, data) |