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

Comparing libev/event.c (file contents):
Revision 1.42 by root, Mon May 10 20:01:45 2010 UTC vs.
Revision 1.48 by root, Wed Nov 10 12:44:22 2010 UTC

1/* 1/*
2 * libevent compatibility layer 2 * libevent compatibility layer
3 * 3 *
4 * Copyright (c) 2007,2008,2009 Marc Alexander Lehmann <libev@schmorp.de> 4 * Copyright (c) 2007,2008,2009,2010 Marc Alexander Lehmann <libev@schmorp.de>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without modifica- 7 * Redistribution and use in source and binary forms, with or without modifica-
8 * tion, are permitted provided that the following conditions are met: 8 * tion, are permitted provided that the following conditions are met:
9 * 9 *
61 int dummy; 61 int dummy;
62}; 62};
63 63
64static struct event_base *ev_x_cur; 64static struct event_base *ev_x_cur;
65 65
66static void
67ev_tv_set (struct timeval *tv, ev_tstamp at)
68{
69 tv->tv_sec = (long)at;
70 tv->tv_usec = (long)((at - (ev_tstamp)tv->tv_sec) * 1e6);
71}
72
73static ev_tstamp 66static ev_tstamp
74ev_tv_get (struct timeval *tv) 67ev_tv_get (struct timeval *tv)
75{ 68{
76 if (tv) 69 if (tv)
77 { 70 {
115void event_base_free (struct event_base *base) 108void event_base_free (struct event_base *base)
116{ 109{
117 dLOOPbase; 110 dLOOPbase;
118 111
119#if EV_MULTIPLICITY 112#if EV_MULTIPLICITY
120 if (ev_default_loop (EVFLAG_AUTO) != loop) 113 if (!is_default_loop (loop))
121 ev_loop_destroy (loop); 114 ev_loop_destroy (loop);
122#endif 115#endif
123} 116}
124 117
125int event_dispatch (void) 118int event_dispatch (void)
145} 138}
146 139
147static void 140static void
148ev_x_cb (struct event *ev, int revents) 141ev_x_cb (struct event *ev, int revents)
149{ 142{
150 revents &= EV_READ | EV_WRITE | EV_TIMEOUT | EV_SIGNAL; 143 revents &= EV_READ | EV_WRITE | EV_TIMER | EV_SIGNAL;
151 144
152 ev->ev_res = revents; 145 ev->ev_res = revents;
153 ev->ev_callback (ev->ev_fd, (short)revents, ev->ev_arg); 146 ev->ev_callback (ev->ev_fd, (short)revents, ev->ev_arg);
154} 147}
155 148
303 if (ev->ev_events & EV_TIMEOUT || ev_is_active (&ev->to) || ev_is_pending (&ev->to)) 296 if (ev->ev_events & EV_TIMEOUT || ev_is_active (&ev->to) || ev_is_pending (&ev->to))
304 { 297 {
305 revents |= EV_TIMEOUT; 298 revents |= EV_TIMEOUT;
306 299
307 if (tv) 300 if (tv)
308 ev_tv_set (tv, ev_now (EV_A)); /* not sure if this is right :) */ 301 {
302 ev_tstamp at = ev_now (EV_A);
303
304 tv->tv_sec = (long)at;
305 tv->tv_usec = (long)((at - (ev_tstamp)tv->tv_sec) * 1e6);
306 }
309 } 307 }
310 308
311 return events & revents; 309 return events & revents;
312} 310}
313 311
332 330
333int event_base_loop (struct event_base *base, int flags) 331int event_base_loop (struct event_base *base, int flags)
334{ 332{
335 dLOOPbase; 333 dLOOPbase;
336 334
337 ev_loop (EV_A_ flags); 335 ev_run (EV_A_ flags);
338 336
339 return 0; 337 return 0;
340} 338}
341 339
342int event_base_dispatch (struct event_base *base) 340int event_base_dispatch (struct event_base *base)
347static void 345static void
348ev_x_loopexit_cb (int revents, void *base) 346ev_x_loopexit_cb (int revents, void *base)
349{ 347{
350 dLOOPbase; 348 dLOOPbase;
351 349
352 ev_unloop (EV_A_ EVUNLOOP_ONE); 350 ev_break (EV_A_ EVBREAK_ONE);
353} 351}
354 352
355int event_base_loopexit (struct event_base *base, struct timeval *tv) 353int event_base_loopexit (struct event_base *base, struct timeval *tv)
356{ 354{
357 ev_tstamp after = ev_tv_get (tv); 355 ev_tstamp after = ev_tv_get (tv);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines