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.7 by root, Thu Dec 20 07:18:17 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines