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.1 by root, Sat Dec 8 02:49:42 2007 UTC vs.
Revision 1.7 by root, Thu Dec 20 07:18:17 2007 UTC

29 29
30 GMainContext *gc; 30 GMainContext *gc;
31}; 31};
32 32
33static void 33static void
34timer_cb (ev_timer *w, int revents) 34timer_cb (EV_P_ ev_timer *w, int revents)
35{ 35{
36 /* nop */ 36 /* nop */
37} 37}
38 38
39static void 39static void
40io_cb (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} 43}
48 44
49static void 45static void
50cleanup (struct econtext *ctx)
51{
52 int i;
53
54 for (i = 0; i < ctx->nfd; ++i)
55 {
56 ev_ref ();
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 ();
65 ev_timer_stop (EV_A_ &ctx->tw);
66 }
67}
68
69static void
70prepare_cb (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 (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 ();
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 } 98 }
123} 99}
124 100
125static void 101static void
126check_cb (ev_check *w, int revents) 102check_cb (EV_P_ ev_check *w, int revents)
127{ 103{
128 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;
129 106
130 cleanup (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);
131 126
132 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);
133 g_main_context_dispatch (ctx->gc);
134} 128}
135 129
136static struct econtext default_context; 130static struct econtext default_context;
137 131
138MODULE = EV::Glib PACKAGE = EV::Glib 132MODULE = EV::Glib PACKAGE = EV::Glib
155 ctx->nfd = 0; 149 ctx->nfd = 0;
156 ctx->afd = 0; 150 ctx->afd = 0;
157 ctx->iow = 0; 151 ctx->iow = 0;
158 ctx->pfd = 0; 152 ctx->pfd = 0;
159 153
160 ev_prepare_init (&ctx->pw, prepare_cb); ev_prepare_start (EV_DEFAULT_ &ctx->pw); 154 ev_prepare_init (&ctx->pw, prepare_cb);
161 ev_check_init (&ctx->cw, check_cb); ev_check_start (EV_DEFAULT_ &ctx->cw); 155 ev_set_priority (&ctx->pw, EV_MINPRI);
162 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);
163} 164}
164 OUTPUT: 165 OUTPUT:
165 RETVAL 166 RETVAL
166 167
167 168

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines