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

Comparing Glib-Event/Event.xs (file contents):
Revision 1.2 by root, Sun Nov 27 19:23:43 2005 UTC vs.
Revision 1.3 by root, Tue Nov 29 16:03:24 2005 UTC

17struct info { 17struct info {
18 int *got_events; 18 int *got_events;
19 pe_io *w; 19 pe_io *w;
20 GPollFD *pfd; 20 GPollFD *pfd;
21}; 21};
22
23static void
24event_timer_cb (pe_event *pe)
25{
26 *(int *)(pe->up->ext_data) = -1;
27}
28 22
29static void 23static void
30event_io_cb (pe_event *pe) 24event_io_cb (pe_event *pe)
31{ 25{
32 U16 got = ((pe_ioevent *)pe)->got; 26 U16 got = ((pe_ioevent *)pe)->got;
48 dSP; 42 dSP;
49 // yes, I use C99. If your compiler barfs here, fix it, but don't 43 // yes, I use C99. If your compiler barfs here, fix it, but don't
50 // tell me your compiler vendor was too incompetent to implement 44 // tell me your compiler vendor was too incompetent to implement
51 // the C standard within the last six years. 45 // the C standard within the last six years.
52 struct info info[nfds]; 46 struct info info[nfds];
53 pe_timer *w_timeout = 0; 47 int got_events = 0;
54 int got_events = 0, got_timeout = 0;
55 int n; 48 int n;
56 49
57 for (n = 0; n < nfds; n++) 50 for (n = 0; n < nfds; n++)
58 { 51 {
59 GPollFD *pfd = fds + n; 52 GPollFD *pfd = fds + n;
72 65
73 pfd->revents = 0; 66 pfd->revents = 0;
74 GEventAPI->start ((pe_watcher *)w, 0); 67 GEventAPI->start ((pe_watcher *)w, 0);
75 } 68 }
76 69
77 if (timeout >= 0)
78 {
79 w_timeout = GEventAPI->new_timer (0, 0);
80 w_timeout->base.callback = (void *)event_timer_cb;
81 w_timeout->base.ext_data = (void *)&got_timeout;
82 w_timeout->tm.at = GEventAPI->NVtime () + timeout * 0.001;
83
84 GEventAPI->start ((pe_watcher *)w_timeout, 0);
85 }
86
87 do { 70 do {
88 PUSHMARK (SP); 71 PUSHMARK (SP);
89 XPUSHs (sv_2mortal (newSVnv (86400))); 72 XPUSHs (sv_2mortal (newSVnv (timeout >= 0 ? timeout * 0.001 : 86400. * 365.)));
90 PUTBACK; 73 PUTBACK;
91 call_pv ("Event::one_event", G_DISCARD | G_EVAL); 74 call_pv ("Event::one_event", G_DISCARD | G_EVAL);
92 SPAGAIN; 75 SPAGAIN;
93 } while (!got_events && !got_timeout); 76 } while (timeout < 0 && !got_events);
94
95 if (w_timeout)
96 GEventAPI->cancel ((pe_watcher *)w_timeout);
97 77
98 for (n = 0; n < nfds; n++) 78 for (n = 0; n < nfds; n++)
99 GEventAPI->cancel ((pe_watcher *)info[n].w); 79 GEventAPI->cancel ((pe_watcher *)info[n].w);
100 80
101 if (SvTRUE (ERRSV)) 81 if (SvTRUE (ERRSV))
102 croak (0); 82 croak (0);
103
104 if (got_timeout)
105 return 0;
106 83
107 return got_events; 84 return got_events;
108} 85}
109 86
110MODULE = Glib::Event PACKAGE = Glib::Event 87MODULE = Glib::Event PACKAGE = Glib::Event

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines