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.4 by root, Sat Dec 8 03:17:46 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
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));
46} 47}
47 48
48static void 49static void
49prepare_cb (EV_P_ ev_prepare *w, int revents) 50check_cb (EV_P_ ev_check *w, int revents)
50{ 51{
51 struct econtext *ctx = (struct econtext *)(((char *)w) - offsetof (struct econtext, pw)); 52 struct econtext *ctx = (struct econtext *)(((char *)w) - offsetof (struct econtext, cw));
52 gint timeout;
53 int i;
54 53
55 if (ctx->nfd >= 0) 54 if (ctx->nfd >= 0)
56 { 55 {
56 int i;
57
57 for (i = 0; i < ctx->nfd; ++i) 58 for (i = 0; i < ctx->nfd; ++i)
58 ev_io_stop (EV_A_ ctx->iow + i); 59 ev_io_stop (EV_A_ ctx->iow + i);
59 60
60 if (ev_is_active (&ctx->tw)) 61 if (ev_is_active (&ctx->tw))
61 ev_timer_stop (EV_A_ &ctx->tw); 62 ev_timer_stop (EV_A_ &ctx->tw);
62 63
63 g_main_context_check (ctx->gc, ctx->maxpri, ctx->pfd, ctx->nfd); 64 g_main_context_check (ctx->gc, ctx->maxpri, ctx->pfd, ctx->nfd);
64 g_main_context_dispatch (ctx->gc);
65 65
66 ctx->nfd = -1; 66 ctx->nfd = -1;
67 } 67 }
68}
69
70static void
71prepare_cb (EV_P_ ev_prepare *w, int revents)
72{
73 struct econtext *ctx = (struct econtext *)(((char *)w) - offsetof (struct econtext, pw));
74 gint timeout;
75 int i;
76
77 check_cb (EV_A_ &ctx->cw, 0);
78
79 g_main_context_dispatch (ctx->gc);
68 80
69 g_main_context_prepare (ctx->gc, &ctx->maxpri); 81 g_main_context_prepare (ctx->gc, &ctx->maxpri);
70 82
71 while (ctx->afd < (ctx->nfd = g_main_context_query ( 83 while (ctx->afd < (ctx->nfd = g_main_context_query (
72 ctx->gc, 84 ctx->gc,
100 pfd->fd, 112 pfd->fd,
101 (pfd->events & G_IO_IN ? EV_READ : 0) 113 (pfd->events & G_IO_IN ? EV_READ : 0)
102 | (pfd->events & G_IO_OUT ? EV_WRITE : 0) 114 | (pfd->events & G_IO_OUT ? EV_WRITE : 0)
103 ); 115 );
104 iow->data = (void *)pfd; 116 iow->data = (void *)pfd;
117 ev_set_priority (&ctx->cw, ev_priority (w) + 1);
105 ev_io_start (EV_A_ iow); 118 ev_io_start (EV_A_ iow);
106 } 119 }
107 120
108 if (timeout >= 0) 121 if (timeout >= 0)
109 { 122 {
136 ctx->iow = 0; 149 ctx->iow = 0;
137 ctx->pfd = 0; 150 ctx->pfd = 0;
138 151
139 ev_prepare_init (&ctx->pw, prepare_cb); 152 ev_prepare_init (&ctx->pw, prepare_cb);
140 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
141 ev_init (&ctx->tw, timer_cb); 159 ev_init (&ctx->tw, timer_cb);
142 ev_set_priority (&ctx->tw, EV_MINPRI); 160 ev_set_priority (&ctx->tw, EV_MINPRI);
143} 161}
144 OUTPUT: 162 OUTPUT:
145 RETVAL 163 RETVAL

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines