X-Git-Url: https://git.llucax.com/software/libev.git/blobdiff_plain/d68da9db1b34dbd6f29a0576bc897a9c49e4d7ed..22b2a449105d7604f715c1afafeb4fe5ac473f1b:/event.c diff --git a/event.c b/event.c index 83fa711..cf7739c 100644 --- a/event.c +++ b/event.c @@ -34,9 +34,8 @@ #include #include -#ifndef EV_EMBED -# include "event.h" -#endif +#include "ev.h" +#include "event.h" #if EV_MULTIPLICITY # define dLOOPev struct ev_loop *loop = (struct ev_loop *)ev->ev_base @@ -88,11 +87,11 @@ void *event_init (void) if (x_cur) x_cur = (struct event_base *)ev_loop_new (EVMETHOD_AUTO); else - x_cur = ev_default_loop (EVMETHOD_AUTO); + x_cur = (struct event_base *)ev_default_loop (EVMETHOD_AUTO); #else assert (("multiple event bases not supported when not compiled with EV_MULTIPLICITY", !x_cur)); - x_cur = (struct event_base *)ev_default_loop (EVMETHOD_AUTO); + x_cur = (struct event_base *)(long)ev_default_loop (EVMETHOD_AUTO); #endif return x_cur; @@ -103,7 +102,8 @@ void event_base_free (struct event_base *base) dLOOPbase; #if EV_MULTIPLICITY - ev_loop_delete (loop); + if (ev_default_loop (EVMETHOD_AUTO) != loop) + ev_loop_destroy (loop); #endif } @@ -112,7 +112,7 @@ int event_dispatch (void) return event_base_dispatch (x_cur); } -#ifdef EV_EMBED +#ifdef EV_STANDALONE void event_set_log_callback (event_log_cb cb) { /* nop */ @@ -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; @@ -226,7 +225,7 @@ int event_del (struct event *ev) if (ev_is_active (&ev->iosig.sig)) ev_signal_stop (EV_A_ &ev->iosig.sig); } - else + else if (ev->ev_events & (EV_READ | EV_WRITE)) { /* io */ if (ev_is_active (&ev->iosig.io)) @@ -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 + else if (ev->ev_events & (EV_READ | EV_WRITE)) { /* 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; @@ -355,7 +354,7 @@ int event_base_once (struct event_base *base, int fd, short events, void (*cb)(i int event_base_priority_init (struct event_base *base, int npri) { - dLOOPbase; + /*dLOOPbase;*/ return 0; }