{
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)
{
{
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)
{
#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
(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
-/* $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.
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;
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;
int ev_pri;
int ev_res;
short ev_events;
-
- char initialised; /* flag to work around some idiosynchrasies in the API */
};
#define EV_PERSIST 0x10
#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)