ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/event.c
(Generate patch)

Comparing libev/event.c (file contents):
Revision 1.15 by root, Sun Nov 4 20:38:07 2007 UTC vs.
Revision 1.19 by root, Tue Nov 6 16:51:20 2007 UTC

29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <stddef.h> 32#include <stddef.h>
33#include <stdlib.h> 33#include <stdlib.h>
34#include <sys/time.h>
35#include <assert.h> 34#include <assert.h>
35
36#ifndef WIN32
37# include <sys/time.h>
38#endif
36 39
37#include "ev.h" 40#include "ev.h"
38#include "event.h" 41#include "event.h"
39 42
40#if EV_MULTIPLICITY 43#if EV_MULTIPLICITY
89 else 92 else
90 x_cur = (struct event_base *)ev_default_loop (EVMETHOD_AUTO); 93 x_cur = (struct event_base *)ev_default_loop (EVMETHOD_AUTO);
91#else 94#else
92 assert (("multiple event bases not supported when not compiled with EV_MULTIPLICITY", !x_cur)); 95 assert (("multiple event bases not supported when not compiled with EV_MULTIPLICITY", !x_cur));
93 96
94 x_cur = (struct event_base *)ev_default_loop (EVMETHOD_AUTO); 97 x_cur = (struct event_base *)(long)ev_default_loop (EVMETHOD_AUTO);
95#endif 98#endif
96 99
97 return x_cur; 100 return x_cur;
98} 101}
99 102
165 x_cb (ev, revents); 168 x_cb (ev, revents);
166} 169}
167 170
168void event_set (struct event *ev, int fd, short events, void (*cb)(int, short, void *), void *arg) 171void event_set (struct event *ev, int fd, short events, void (*cb)(int, short, void *), void *arg)
169{ 172{
170 printf ("event set %p\n", ev);//D
171 if (events & EV_SIGNAL) 173 if (events & EV_SIGNAL)
172 ev_watcher_init (&ev->iosig.sig, x_cb_sig); 174 ev_watcher_init (&ev->iosig.sig, x_cb_sig);
173 else 175 else
174 ev_watcher_init (&ev->iosig.io, x_cb_io); 176 ev_watcher_init (&ev->iosig.io, x_cb_io);
175 177
189 return event_base_once (x_cur, fd, events, cb, arg, tv); 191 return event_base_once (x_cur, fd, events, cb, arg, tv);
190} 192}
191 193
192int event_add (struct event *ev, struct timeval *tv) 194int event_add (struct event *ev, struct timeval *tv)
193{ 195{
194 printf ("event add %p %p\n", ev, &ev->to);//D
195 dLOOPev; 196 dLOOPev;
196 197
197 /* disable all watchers */ 198 /* disable all watchers */
198 event_del (ev); 199 event_del (ev);
199 200
217 return 0; 218 return 0;
218} 219}
219 220
220int event_del (struct event *ev) 221int event_del (struct event *ev)
221{ 222{
222 printf ("event del %p\n", ev);//D
223 dLOOPev; 223 dLOOPev;
224 224
225 if (ev->ev_events & EV_SIGNAL) 225 if (ev->ev_events & EV_SIGNAL)
226 { 226 {
227 /* sig */ 227 /* sig */
228 if (ev_is_active (&ev->iosig.sig)) 228 if (ev_is_active (&ev->iosig.sig))
229 ev_signal_stop (EV_A_ &ev->iosig.sig); 229 ev_signal_stop (EV_A_ &ev->iosig.sig);
230 } 230 }
231 else 231 else if (ev->ev_events & (EV_READ | EV_WRITE))
232 { 232 {
233 /* io */ 233 /* io */
234 if (ev_is_active (&ev->iosig.io)) 234 if (ev_is_active (&ev->iosig.io))
235 ev_io_stop (EV_A_ &ev->iosig.io); 235 ev_io_stop (EV_A_ &ev->iosig.io);
236 } 236 }
237 237
238 printf ("to %p %d\n", &ev->to, ev->to.active);//D
239 if (ev_is_active (&ev->to)) 238 if (ev_is_active (&ev->to))
240 ev_timer_stop (EV_A_ &ev->to); 239 ev_timer_stop (EV_A_ &ev->to);
241 240
242 return 0; 241 return 0;
243} 242}
244 243
245int event_pending (struct event *ev, short events, struct timeval *tv) 244int event_pending (struct event *ev, short events, struct timeval *tv)
246{ 245{
246 short revents = 0;
247 dLOOPev; 247 dLOOPev;
248 248
249 short revents = 0;
250 249
251 if (ev->ev_events & EV_SIGNAL) 250 if (ev->ev_events & EV_SIGNAL)
252 { 251 {
253 /* sig */ 252 /* sig */
254 if (ev_is_active (&ev->iosig.sig) || ev_is_pending (&ev->iosig.sig)) 253 if (ev_is_active (&ev->iosig.sig) || ev_is_pending (&ev->iosig.sig))
255 revents |= EV_SIGNAL; 254 revents |= EV_SIGNAL;
256 } 255 }
257 else 256 else if (ev->ev_events & (EV_READ | EV_WRITE))
258 { 257 {
259 /* io */ 258 /* io */
260 if (ev_is_active (&ev->iosig.io) || ev_is_pending (&ev->iosig.io)) 259 if (ev_is_active (&ev->iosig.io) || ev_is_pending (&ev->iosig.io))
261 revents |= ev->ev_events & (EV_READ | EV_WRITE); 260 revents |= ev->ev_events & (EV_READ | EV_WRITE);
262 } 261 }
313 ev_unloop (EV_A_ EVUNLOOP_ONCE); 312 ev_unloop (EV_A_ EVUNLOOP_ONCE);
314} 313}
315 314
316int event_base_loopexit (struct event_base *base, struct timeval *tv) 315int event_base_loopexit (struct event_base *base, struct timeval *tv)
317{ 316{
318 dLOOPbase;
319 ev_tstamp after = tv_get (tv); 317 ev_tstamp after = tv_get (tv);
318 dLOOPbase;
320 319
321 ev_once (EV_A_ -1, 0, after >= 0. ? after : 0., x_loopexit_cb, (void *)base); 320 ev_once (EV_A_ -1, 0, after >= 0. ? after : 0., x_loopexit_cb, (void *)base);
322 321
323 return -1; 322 return -1;
324} 323}
331}; 330};
332 331
333static void 332static void
334x_once_cb (int revents, void *arg) 333x_once_cb (int revents, void *arg)
335{ 334{
336 struct x_once *once = arg; 335 struct x_once *once = (struct x_once *)arg;
337 336
338 once->cb (once->fd, revents, once->arg); 337 once->cb (once->fd, revents, once->arg);
339 free (once); 338 free (once);
340} 339}
341 340
342int event_base_once (struct event_base *base, int fd, short events, void (*cb)(int, short, void *), void *arg, struct timeval *tv) 341int event_base_once (struct event_base *base, int fd, short events, void (*cb)(int, short, void *), void *arg, struct timeval *tv)
343{ 342{
344 dLOOPbase;
345 struct x_once *once = malloc (sizeof (struct x_once)); 343 struct x_once *once = (struct x_once *)malloc (sizeof (struct x_once));
344 dLOOPbase;
346 345
347 if (!once) 346 if (!once)
348 return -1; 347 return -1;
349 348
350 once->fd = fd; 349 once->fd = fd;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines