Browse Source

*** empty log message ***

master
Marc Alexander Lehmann 13 years ago
parent
commit
548cbcc6ce
  1. 3
      Changes
  2. 70
      event.c

3
Changes

@ -17,7 +17,8 @@ WISH? monotonic clocks times/GetTickCount for coarse corrections?
to have a struct AND a function called ev_loop).
- fix a bug where ev_default would not initialise the default
loop again after it was destroyed with ev_default_destroy.
- rename syserr to ev_syserr to avoid name clashes when embedding.
- rename syserr to ev_syserr to avoid name clashes when embedding,
do similar changes for event.c.
3.45 Tue Oct 21 21:59:26 CEST 2008
- disable inotify usage on linux <2.6.25, as it is broken

70
event.c

@ -65,17 +65,17 @@ struct event_base
int dummy;
};
static struct event_base *x_cur;
static struct event_base *ev_x_cur;
static void
tv_set (struct timeval *tv, ev_tstamp at)
ev_tv_set (struct timeval *tv, ev_tstamp at)
{
tv->tv_sec = (long)at;
tv->tv_usec = (long)((at - (ev_tstamp)tv->tv_sec) * 1e6);
}
static ev_tstamp
tv_get (struct timeval *tv)
ev_tv_get (struct timeval *tv)
{
if (tv)
return tv->tv_sec + tv->tv_usec * 1e-6;
@ -98,17 +98,17 @@ const char *event_get_method (void)
void *event_init (void)
{
#if EV_MULTIPLICITY
if (x_cur)
x_cur = (struct event_base *)ev_loop_new (EVFLAG_AUTO);
if (ev_x_cur)
ev_x_cur = (struct event_base *)ev_loop_new (EVFLAG_AUTO);
else
x_cur = (struct event_base *)ev_default_loop (EVFLAG_AUTO);
ev_x_cur = (struct event_base *)ev_default_loop (EVFLAG_AUTO);
#else
assert (("multiple event bases not supported when not compiled with EV_MULTIPLICITY", !x_cur));
assert (("multiple event bases not supported when not compiled with EV_MULTIPLICITY", !ev_x_cur));
x_cur = (struct event_base *)(long)ev_default_loop (EVFLAG_AUTO);
ev_x_cur = (struct event_base *)(long)ev_default_loop (EVFLAG_AUTO);
#endif
return x_cur;
return ev_x_cur;
}
void event_base_free (struct event_base *base)
@ -123,7 +123,7 @@ void event_base_free (struct event_base *base)
int event_dispatch (void)
{
return event_base_dispatch (x_cur);
return event_base_dispatch (ev_x_cur);
}
#ifdef EV_STANDALONE
@ -135,16 +135,16 @@ void event_set_log_callback (event_log_cb cb)
int event_loop (int flags)
{
return event_base_loop (x_cur, flags);
return event_base_loop (ev_x_cur, flags);
}
int event_loopexit (struct timeval *tv)
{
return event_base_loopexit (x_cur, tv);
return event_base_loopexit (ev_x_cur, tv);
}
static void
x_cb (struct event *ev, int revents)
ev_x_cb (struct event *ev, int revents)
{
revents &= EV_READ | EV_WRITE | EV_TIMEOUT | EV_SIGNAL;
@ -153,47 +153,47 @@ x_cb (struct event *ev, int revents)
}
static void
x_cb_sig (EV_P_ struct ev_signal *w, int revents)
ev_x_cb_sig (EV_P_ struct ev_signal *w, int revents)
{
struct event *ev = (struct event *)(((char *)w) - offsetof (struct event, iosig.sig));
if (revents & EV_ERROR)
event_del (ev);
x_cb (ev, revents);
ev_x_cb (ev, revents);
}
static void
x_cb_io (EV_P_ struct ev_io *w, int revents)
ev_x_cb_io (EV_P_ struct ev_io *w, int revents)
{
struct event *ev = (struct event *)(((char *)w) - offsetof (struct event, iosig.io));
if ((revents & EV_ERROR) || !(ev->ev_events & EV_PERSIST))
event_del (ev);
x_cb (ev, revents);
ev_x_cb (ev, revents);
}
static void
x_cb_to (EV_P_ struct ev_timer *w, int revents)
ev_x_cb_to (EV_P_ struct ev_timer *w, int revents)
{
struct event *ev = (struct event *)(((char *)w) - offsetof (struct event, to));
event_del (ev);
x_cb (ev, revents);
ev_x_cb (ev, revents);
}
void event_set (struct event *ev, int fd, short events, void (*cb)(int, short, void *), void *arg)
{
if (events & EV_SIGNAL)
ev_init (&ev->iosig.sig, x_cb_sig);
ev_init (&ev->iosig.sig, ev_x_cb_sig);
else
ev_init (&ev->iosig.io, x_cb_io);
ev_init (&ev->iosig.io, ev_x_cb_io);
ev_init (&ev->to, x_cb_to);
ev_init (&ev->to, ev_x_cb_to);
ev->ev_base = x_cur; /* not threadsafe, but its like libevent works */
ev->ev_base = ev_x_cur; /* not threadsafe, but it's how libevent works */
ev->ev_fd = fd;
ev->ev_events = events;
ev->ev_pri = 0;
@ -205,7 +205,7 @@ void event_set (struct event *ev, int fd, short events, void (*cb)(int, short, v
int event_once (int fd, short events, void (*cb)(int, short, void *), void *arg, struct timeval *tv)
{
return event_base_once (x_cur, fd, events, cb, arg, tv);
return event_base_once (ev_x_cur, fd, events, cb, arg, tv);
}
int event_add (struct event *ev, struct timeval *tv)
@ -235,7 +235,7 @@ int event_add (struct event *ev, struct timeval *tv)
if (tv)
{
ev->to.repeat = tv_get (tv);
ev->to.repeat = ev_tv_get (tv);
ev_timer_again (EV_A_ &ev->to);
ev->ev_flags |= EVLIST_TIMEOUT;
}
@ -304,7 +304,7 @@ int event_pending (struct event *ev, short events, struct timeval *tv)
revents |= EV_TIMEOUT;
if (tv)
tv_set (tv, ev_now (EV_A)); /* not sure if this is right :) */
ev_tv_set (tv, ev_now (EV_A)); /* not sure if this is right :) */
}
return events & revents;
@ -312,7 +312,7 @@ int event_pending (struct event *ev, short events, struct timeval *tv)
int event_priority_init (int npri)
{
return event_base_priority_init (x_cur, npri);
return event_base_priority_init (ev_x_cur, npri);
}
int event_priority_set (struct event *ev, int pri)
@ -344,7 +344,7 @@ int event_base_dispatch (struct event_base *base)
}
static void
x_loopexit_cb (int revents, void *base)
ev_x_loopexit_cb (int revents, void *base)
{
dLOOPbase;
@ -353,15 +353,15 @@ x_loopexit_cb (int revents, void *base)
int event_base_loopexit (struct event_base *base, struct timeval *tv)
{
ev_tstamp after = tv_get (tv);
ev_tstamp after = ev_tv_get (tv);
dLOOPbase;
ev_once (EV_A_ -1, 0, after >= 0. ? after : 0., x_loopexit_cb, (void *)base);
ev_once (EV_A_ -1, 0, after >= 0. ? after : 0., ev_x_loopexit_cb, (void *)base);
return 0;
}
struct x_once
struct ev_x_once
{
int fd;
void (*cb)(int, short, void *);
@ -369,9 +369,9 @@ struct x_once
};
static void
x_once_cb (int revents, void *arg)
ev_x_once_cb (int revents, void *arg)
{
struct x_once *once = (struct x_once *)arg;
struct ev_x_once *once = (struct ev_x_once *)arg;
once->cb (once->fd, (short)revents, once->arg);
free (once);
@ -379,7 +379,7 @@ x_once_cb (int revents, void *arg)
int event_base_once (struct event_base *base, int fd, short events, void (*cb)(int, short, void *), void *arg, struct timeval *tv)
{
struct x_once *once = (struct x_once *)malloc (sizeof (struct x_once));
struct ev_x_once *once = (struct ev_x_once *)malloc (sizeof (struct ev_x_once));
dLOOPbase;
if (!once)
@ -389,7 +389,7 @@ int event_base_once (struct event_base *base, int fd, short events, void (*cb)(i
once->cb = cb;
once->arg = arg;
ev_once (EV_A_ fd, events & (EV_READ | EV_WRITE), tv_get (tv), x_once_cb, (void *)once);
ev_once (EV_A_ fd, events & (EV_READ | EV_WRITE), ev_tv_get (tv), ev_x_once_cb, (void *)once);
return 0;
}

Loading…
Cancel
Save