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.2 by root, Sat Dec 8 02:59:43 2007 UTC vs.
Revision 1.5 by root, Sat Dec 8 03:40:32 2007 UTC

45 ((revents & EV_READ ? G_IO_IN : 0) 45 ((revents & EV_READ ? G_IO_IN : 0)
46 | (revents & EV_READ ? G_IO_OUT : 0)); 46 | (revents & EV_READ ? G_IO_OUT : 0));
47} 47}
48 48
49static void 49static void
50cleanup (EV_P_ struct econtext *ctx) 50check_cb (EV_P_ ev_check *w, int revents)
51{ 51{
52 int i; 52 struct econtext *ctx = (struct econtext *)(((char *)w) - offsetof (struct econtext, cw));
53 53
54 for (i = 0; i < ctx->nfd; ++i) 54 if (ctx->nfd >= 0)
55 { 55 {
56 ev_ref (EV_A); 56 int i;
57 ev_io_stop (EV_A_ ctx->iow + i);
58 }
59 57
60 ctx->nfd = 0; 58 for (i = 0; i < ctx->nfd; ++i)
59 ev_io_stop (EV_A_ ctx->iow + i);
61 60
62 if (ev_is_active (&ctx->tw)) 61 if (ev_is_active (&ctx->tw))
63 {
64 ev_ref (EV_A);
65 ev_timer_stop (EV_A_ &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;
66 } 67 }
67} 68}
68 69
69static void 70static void
70prepare_cb (EV_P_ ev_prepare *w, int revents) 71prepare_cb (EV_P_ ev_prepare *w, int revents)
71{ 72{
72 struct econtext *ctx = (struct econtext *)(((char *)w) - offsetof (struct econtext, pw)); 73 struct econtext *ctx = (struct econtext *)(((char *)w) - offsetof (struct econtext, pw));
73 gint timeout; 74 gint timeout;
74 int n; 75 int i;
75 76
76 cleanup (EV_A_ ctx); 77 check_cb (EV_A_ &ctx->cw, 0);
78
79 g_main_context_dispatch (ctx->gc);
77 80
78 g_main_context_prepare (ctx->gc, &ctx->maxpri); 81 g_main_context_prepare (ctx->gc, &ctx->maxpri);
79 82
80 while (ctx->afd < (ctx->nfd = g_main_context_query ( 83 while (ctx->afd < (ctx->nfd = g_main_context_query (
81 ctx->gc, 84 ctx->gc,
94 97
95 ctx->pfd = malloc (ctx->afd * sizeof (GPollFD)); 98 ctx->pfd = malloc (ctx->afd * sizeof (GPollFD));
96 ctx->iow = malloc (ctx->afd * sizeof (ev_io)); 99 ctx->iow = malloc (ctx->afd * sizeof (ev_io));
97 } 100 }
98 101
99 for (n = 0; n < ctx->nfd; ++n) 102 for (i = 0; i < ctx->nfd; ++i)
100 { 103 {
101 GPollFD *pfd = ctx->pfd + n; 104 GPollFD *pfd = ctx->pfd + i;
102 ev_io *iow = ctx->iow + n; 105 ev_io *iow = ctx->iow + i;
103 106
104 pfd->revents = 0; 107 pfd->revents = 0;
105 108
106 ev_io_init ( 109 ev_io_init (
107 iow, 110 iow,
109 pfd->fd, 112 pfd->fd,
110 (pfd->events & G_IO_IN ? EV_READ : 0) 113 (pfd->events & G_IO_IN ? EV_READ : 0)
111 | (pfd->events & G_IO_OUT ? EV_WRITE : 0) 114 | (pfd->events & G_IO_OUT ? EV_WRITE : 0)
112 ); 115 );
113 iow->data = (void *)pfd; 116 iow->data = (void *)pfd;
117 ev_set_priority (&ctx->cw, ev_priority (w) + 1);
114 ev_io_start (EV_A_ iow); 118 ev_io_start (EV_A_ iow);
115 ev_unref (EV_A);
116 } 119 }
117 120
118 if (timeout >= 0) 121 if (timeout >= 0)
119 { 122 {
120 ev_timer_set (&ctx->tw, timeout * 1e-3, 0.); 123 ev_timer_set (&ctx->tw, timeout * 1e-3, 0.);
121 ev_timer_start (EV_A_ &ctx->tw); 124 ev_timer_start (EV_A_ &ctx->tw);
122 ev_unref (EV_A);
123 } 125 }
124}
125
126static void
127check_cb (EV_P_ ev_check *w, int revents)
128{
129 struct econtext *ctx = (struct econtext *)(((char *)w) - offsetof (struct econtext, cw));
130
131 cleanup (EV_A_ ctx);
132
133 g_main_context_check (ctx->gc, ctx->maxpri, ctx->pfd, ctx->nfd);
134 g_main_context_dispatch (ctx->gc);
135} 126}
136 127
137static struct econtext default_context; 128static struct econtext default_context;
138 129
139MODULE = EV::Glib PACKAGE = EV::Glib 130MODULE = EV::Glib PACKAGE = EV::Glib
151{ 142{
152 GMainContext *gc = get_gcontext (context); 143 GMainContext *gc = get_gcontext (context);
153 struct econtext *ctx = &default_context; 144 struct econtext *ctx = &default_context;
154 145
155 ctx->gc = g_main_context_ref (gc); 146 ctx->gc = g_main_context_ref (gc);
156 ctx->nfd = 0; 147 ctx->nfd = -1;
157 ctx->afd = 0; 148 ctx->afd = 0;
158 ctx->iow = 0; 149 ctx->iow = 0;
159 ctx->pfd = 0; 150 ctx->pfd = 0;
160 151
161 ev_prepare_init (&ctx->pw, prepare_cb); ev_prepare_start (EV_DEFAULT_ &ctx->pw); 152 ev_prepare_init (&ctx->pw, prepare_cb);
162 ev_check_init (&ctx->cw, check_cb); ev_check_start (EV_DEFAULT_ &ctx->cw); 153 ev_prepare_start (EV_DEFAULT_ &ctx->pw);
163 ev_init (&ctx->tw, timer_cb); ev_set_priority (&ctx->tw, EV_MINPRI); 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
159 ev_init (&ctx->tw, timer_cb);
160 ev_set_priority (&ctx->tw, EV_MINPRI);
164} 161}
165 OUTPUT: 162 OUTPUT:
166 RETVAL 163 RETVAL
167 164
168 165

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines