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

Comparing cvsroot/Glib-EV/EV.xs (file contents):
Revision 1.1 by root, Sat Nov 24 16:10:22 2007 UTC vs.
Revision 1.2 by root, Sat Dec 8 02:58:27 2007 UTC

13 13
14 croak ("only the default context is currently supported."); 14 croak ("only the default context is currently supported.");
15} 15}
16 16
17static void 17static void
18timeout_cb (ev_timer *w, int revents) 18timeout_cb (EV_P_ ev_timer *w, int revents)
19{ 19{
20 ev_unloop (EVUNLOOP_ONE); 20 ev_unloop (EV_A_ EVUNLOOP_ONE);
21} 21}
22 22
23typedef struct 23typedef struct
24{ 24{
25 struct ev_io io; 25 struct ev_io io;
26 int *got_events; 26 int *got_events;
27 GPollFD *pfd; 27 GPollFD *pfd;
28} slot; 28} slot;
29 29
30static void 30static void
31io_cb (ev_io *w, int revents) 31io_cb (EV_P_ ev_io *w, int revents)
32{ 32{
33 slot *s = (slot *)w; 33 slot *s = (slot *)w;
34 int oev = s->pfd->revents;
34 35
35 s->pfd->revents |= s->pfd->events & 36 s->pfd->revents |= s->pfd->events &
36 ((revents & EV_READ ? G_IO_IN : 0) 37 ((revents & EV_READ ? G_IO_IN : 0)
37 | (revents & EV_READ ? G_IO_OUT : 0)); 38 | (revents & EV_READ ? G_IO_OUT : 0));
38 39
39 if (s->pfd->revents) 40 if (!oev && s->pfd->revents)
40 ++*(s->got_events); 41 ++*(s->got_events);
41 42
42 ev_unloop (EVUNLOOP_ONE); 43 ev_unloop (EV_A_ EVUNLOOP_ONE);
43} 44}
44 45
45static gint 46static gint
46event_poll_func (GPollFD *fds, guint nfds, gint timeout) 47event_poll_func (GPollFD *fds, guint nfds, gint timeout)
47{ 48{
69 io_cb, 70 io_cb,
70 pfd->fd, 71 pfd->fd,
71 (pfd->events & G_IO_IN ? EV_READ : 0) 72 (pfd->events & G_IO_IN ? EV_READ : 0)
72 | (pfd->events & G_IO_OUT ? EV_WRITE : 0) 73 | (pfd->events & G_IO_OUT ? EV_WRITE : 0)
73 ); 74 );
74 ev_io_start (&s->io); 75 ev_io_start (EV_A_ &s->io);
75 } 76 }
76 77
77 if (timeout >= 0) 78 if (timeout >= 0)
78 { 79 {
79 ev_timer_init (&to, timeout_cb, timeout * 1e-3, 0.); 80 ev_timer_init (&to, timeout_cb, timeout * 1e-3, 0.);
80 ev_timer_start (&to); 81 ev_timer_start (EV_A_ &to);
81 } 82 }
82 83
83 ev_loop (0); 84 ev_loop (EV_A_ 0);
84 85
85 if (timeout >= 0) 86 if (timeout >= 0)
86 ev_timer_stop (&to); 87 ev_timer_stop (EV_A_ &to);
87 88
88 for (n = 0; n < nfds; ++n) 89 for (n = 0; n < nfds; ++n)
89 ev_io_stop (&slots[n].io); 90 ev_io_stop (EV_A_ &slots[n].io);
90 91
91 return got_events; 92 return got_events;
92} 93}
93 94
94MODULE = Glib::EV PACKAGE = Glib::EV 95MODULE = Glib::EV PACKAGE = Glib::EV

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines