--- EV-Glib/Glib.xs 2007/12/08 02:59:43 1.2 +++ EV-Glib/Glib.xs 2007/12/08 03:17:40 1.3 @@ -24,7 +24,6 @@ gint maxpri; ev_prepare pw; - ev_check cw; ev_timer tw; GMainContext *gc; @@ -44,36 +43,30 @@ pfd->revents |= pfd->events & ((revents & EV_READ ? G_IO_IN : 0) | (revents & EV_READ ? G_IO_OUT : 0)); + + printf ("ctx rev %d %x:%x\n", w->fd, pfd->events, pfd->revents);//D } static void -cleanup (EV_P_ struct econtext *ctx) +prepare_cb (EV_P_ ev_prepare *w, int revents) { + struct econtext *ctx = (struct econtext *)(((char *)w) - offsetof (struct econtext, pw)); + gint timeout; int i; - for (i = 0; i < ctx->nfd; ++i) + if (ctx->nfd >= 0) { - ev_ref (EV_A); - ev_io_stop (EV_A_ ctx->iow + i); - } + for (i = 0; i < ctx->nfd; ++i) + ev_io_stop (EV_A_ ctx->iow + i); - ctx->nfd = 0; + if (ev_is_active (&ctx->tw)) + ev_timer_stop (EV_A_ &ctx->tw); - if (ev_is_active (&ctx->tw)) - { - ev_ref (EV_A); - ev_timer_stop (EV_A_ &ctx->tw); - } -} + g_main_context_check (ctx->gc, ctx->maxpri, ctx->pfd, ctx->nfd); + g_main_context_dispatch (ctx->gc); -static void -prepare_cb (EV_P_ ev_prepare *w, int revents) -{ - struct econtext *ctx = (struct econtext *)(((char *)w) - offsetof (struct econtext, pw)); - gint timeout; - int n; - - cleanup (EV_A_ ctx); + ctx->nfd = -1; + } g_main_context_prepare (ctx->gc, &ctx->maxpri); @@ -96,10 +89,10 @@ ctx->iow = malloc (ctx->afd * sizeof (ev_io)); } - for (n = 0; n < ctx->nfd; ++n) + for (i = 0; i < ctx->nfd; ++i) { - GPollFD *pfd = ctx->pfd + n; - ev_io *iow = ctx->iow + n; + GPollFD *pfd = ctx->pfd + i; + ev_io *iow = ctx->iow + i; pfd->revents = 0; @@ -112,28 +105,15 @@ ); iow->data = (void *)pfd; ev_io_start (EV_A_ iow); - ev_unref (EV_A); } if (timeout >= 0) { ev_timer_set (&ctx->tw, timeout * 1e-3, 0.); ev_timer_start (EV_A_ &ctx->tw); - ev_unref (EV_A); } } -static void -check_cb (EV_P_ ev_check *w, int revents) -{ - struct econtext *ctx = (struct econtext *)(((char *)w) - offsetof (struct econtext, cw)); - - cleanup (EV_A_ ctx); - - g_main_context_check (ctx->gc, ctx->maxpri, ctx->pfd, ctx->nfd); - g_main_context_dispatch (ctx->gc); -} - static struct econtext default_context; MODULE = EV::Glib PACKAGE = EV::Glib @@ -153,14 +133,15 @@ struct econtext *ctx = &default_context; ctx->gc = g_main_context_ref (gc); - ctx->nfd = 0; + ctx->nfd = -1; ctx->afd = 0; ctx->iow = 0; ctx->pfd = 0; - ev_prepare_init (&ctx->pw, prepare_cb); ev_prepare_start (EV_DEFAULT_ &ctx->pw); - ev_check_init (&ctx->cw, check_cb); ev_check_start (EV_DEFAULT_ &ctx->cw); - ev_init (&ctx->tw, timer_cb); ev_set_priority (&ctx->tw, EV_MINPRI); + ev_prepare_init (&ctx->pw, prepare_cb); + ev_prepare_start (EV_DEFAULT_ &ctx->pw); + ev_init (&ctx->tw, timer_cb); + ev_set_priority (&ctx->tw, EV_MINPRI); } OUTPUT: RETVAL