ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV-Glib/Glib.xs
(Generate patch)

Comparing EV-Glib/Glib.xs (file contents):
Revision 1.3 by root, Sat Dec 8 03:17:40 2007 UTC vs.
Revision 1.5 by root, Sat Dec 8 03:40:32 2007 UTC

22 ev_io *iow; 22 ev_io *iow;
23 int nfd, afd; 23 int nfd, afd;
24 gint maxpri; 24 gint maxpri;
25 25
26 ev_prepare pw; 26 ev_prepare pw;
27 ev_check cw;
27 ev_timer tw; 28 ev_timer tw;
28 29
29 GMainContext *gc; 30 GMainContext *gc;
30}; 31};
31 32
41 GPollFD *pfd = (GPollFD *)w->data; 42 GPollFD *pfd = (GPollFD *)w->data;
42 43
43 pfd->revents |= pfd->events & 44 pfd->revents |= pfd->events &
44 ((revents & EV_READ ? G_IO_IN : 0) 45 ((revents & EV_READ ? G_IO_IN : 0)
45 | (revents & EV_READ ? G_IO_OUT : 0)); 46 | (revents & EV_READ ? G_IO_OUT : 0));
47}
46 48
47 printf ("ctx rev %d %x:%x\n", w->fd, pfd->events, pfd->revents);//D 49static void
50check_cb (EV_P_ ev_check *w, int revents)
51{
52 struct econtext *ctx = (struct econtext *)(((char *)w) - offsetof (struct econtext, cw));
53
54 if (ctx->nfd >= 0)
55 {
56 int i;
57
58 for (i = 0; i < ctx->nfd; ++i)
59 ev_io_stop (EV_A_ ctx->iow + i);
60
61 if (ev_is_active (&ctx->tw))
62 ev_timer_stop (EV_A_ &ctx->tw);
63
64 g_main_context_check (ctx->gc, ctx->maxpri, ctx->pfd, ctx->nfd);
65
66 ctx->nfd = -1;
67 }
48} 68}
49 69
50static void 70static void
51prepare_cb (EV_P_ ev_prepare *w, int revents) 71prepare_cb (EV_P_ ev_prepare *w, int revents)
52{ 72{
53 struct econtext *ctx = (struct econtext *)(((char *)w) - offsetof (struct econtext, pw)); 73 struct econtext *ctx = (struct econtext *)(((char *)w) - offsetof (struct econtext, pw));
54 gint timeout; 74 gint timeout;
55 int i; 75 int i;
56 76
57 if (ctx->nfd >= 0) 77 check_cb (EV_A_ &ctx->cw, 0);
58 {
59 for (i = 0; i < ctx->nfd; ++i)
60 ev_io_stop (EV_A_ ctx->iow + i);
61 78
62 if (ev_is_active (&ctx->tw))
63 ev_timer_stop (EV_A_ &ctx->tw);
64
65 g_main_context_check (ctx->gc, ctx->maxpri, ctx->pfd, ctx->nfd);
66 g_main_context_dispatch (ctx->gc); 79 g_main_context_dispatch (ctx->gc);
67
68 ctx->nfd = -1;
69 }
70 80
71 g_main_context_prepare (ctx->gc, &ctx->maxpri); 81 g_main_context_prepare (ctx->gc, &ctx->maxpri);
72 82
73 while (ctx->afd < (ctx->nfd = g_main_context_query ( 83 while (ctx->afd < (ctx->nfd = g_main_context_query (
74 ctx->gc, 84 ctx->gc,
102 pfd->fd, 112 pfd->fd,
103 (pfd->events & G_IO_IN ? EV_READ : 0) 113 (pfd->events & G_IO_IN ? EV_READ : 0)
104 | (pfd->events & G_IO_OUT ? EV_WRITE : 0) 114 | (pfd->events & G_IO_OUT ? EV_WRITE : 0)
105 ); 115 );
106 iow->data = (void *)pfd; 116 iow->data = (void *)pfd;
117 ev_set_priority (&ctx->cw, ev_priority (w) + 1);
107 ev_io_start (EV_A_ iow); 118 ev_io_start (EV_A_ iow);
108 } 119 }
109 120
110 if (timeout >= 0) 121 if (timeout >= 0)
111 { 122 {
138 ctx->iow = 0; 149 ctx->iow = 0;
139 ctx->pfd = 0; 150 ctx->pfd = 0;
140 151
141 ev_prepare_init (&ctx->pw, prepare_cb); 152 ev_prepare_init (&ctx->pw, prepare_cb);
142 ev_prepare_start (EV_DEFAULT_ &ctx->pw); 153 ev_prepare_start (EV_DEFAULT_ &ctx->pw);
154
155 ev_check_init (&ctx->cw, check_cb);
156 ev_set_priority (&ctx->cw, EV_MAXPRI - 1);
157 ev_check_start (EV_DEFAULT_ &ctx->cw);
158
143 ev_init (&ctx->tw, timer_cb); 159 ev_init (&ctx->tw, timer_cb);
144 ev_set_priority (&ctx->tw, EV_MINPRI); 160 ev_set_priority (&ctx->tw, EV_MINPRI);
145} 161}
146 OUTPUT: 162 OUTPUT:
147 RETVAL 163 RETVAL

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines