From c04c7d0577ceddfe470b6fdcaf727ced91a67d1a Mon Sep 17 00:00:00 2001 From: root Date: Sun, 4 Nov 2007 19:45:09 +0000 Subject: [PATCH] *** empty log message *** --- ev.c | 4 ++++ ev.h | 1 + ev_epoll.c | 3 ++- evdns.c | 2 +- event.c | 27 +++++++++++++-------------- event.h | 4 +--- 6 files changed, 22 insertions(+), 19 deletions(-) diff --git a/ev.c b/ev.c index 7af2358..83c643a 100644 --- a/ev.c +++ b/ev.c @@ -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) { diff --git a/ev.h b/ev.h index 5a9462c..109e211 100644 --- a/ev.h +++ b/ev.h @@ -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 diff --git a/ev_epoll.c b/ev_epoll.c index 8bc8658..bdd746b 100644 --- a/ev_epoll.c +++ b/ev_epoll.c @@ -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 diff --git a/evdns.c b/evdns.c index f8ef2a1..e4e4e8f 100644 --- a/evdns.c +++ b/evdns.c @@ -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. diff --git a/event.c b/event.c index 030df49..98260d6 100644 --- a/event.c +++ b/event.c @@ -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; diff --git a/event.h b/event.h index 7566438..5226924 100644 --- a/event.h +++ b/event.h @@ -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) -- 2.43.0