#include <sys/time.h>
#include <assert.h>
-#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
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));
dLOOPbase;
#if EV_MULTIPLICITY
- ev_loop_delete (loop);
+ if (ev_default_loop (EVMETHOD_AUTO) != loop)
+ ev_loop_destroy (loop);
#endif
}
return event_base_dispatch (x_cur);
}
-#ifdef EV_EMBED
+#ifdef EV_STANDALONE
void event_set_log_callback (event_log_cb cb)
{
/* nop */
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_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))
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;
int event_base_priority_init (struct event_base *base, int npri)
{
- dLOOPbase;
+ /*dLOOPbase;*/
return 0;
}