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

Comparing libev/event.c (file contents):
Revision 1.41 by root, Wed Jan 7 20:45:52 2009 UTC vs.
Revision 1.46 by root, Sun Oct 24 17:19:47 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 *
45# include EV_EVENT_H 45# include EV_EVENT_H
46#else 46#else
47# include "event.h" 47# include "event.h"
48#endif 48#endif
49 49
50/* same definition as in ev.c */
51#define EV_TV_SET(tv,t) do { tv.tv_sec = (long)t; tv.tv_usec = (long)((t - tv.tv_sec) * 1e6); } while (0)
52
50#if EV_MULTIPLICITY 53#if EV_MULTIPLICITY
51# define dLOOPev struct ev_loop *loop = (struct ev_loop *)ev->ev_base 54# define dLOOPev struct ev_loop *loop = (struct ev_loop *)ev->ev_base
52# define dLOOPbase struct ev_loop *loop = (struct ev_loop *)base 55# define dLOOPbase struct ev_loop *loop = (struct ev_loop *)base
53#else 56#else
54# define dLOOPev 57# define dLOOPev
61 int dummy; 64 int dummy;
62}; 65};
63 66
64static struct event_base *ev_x_cur; 67static struct event_base *ev_x_cur;
65 68
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 69static ev_tstamp
74ev_tv_get (struct timeval *tv) 70ev_tv_get (struct timeval *tv)
75{ 71{
76 if (tv) 72 if (tv)
73 {
77 return tv->tv_sec + tv->tv_usec * 1e-6; 74 ev_tstamp after = tv->tv_sec + tv->tv_usec * 1e-6;
75 return after ? after : 1e-6;
76 }
78 else 77 else
79 return -1.; 78 return -1.;
80} 79}
81 80
82#define EVENT_STRINGIFY(s) # s 81#define EVENT_STRINGIFY(s) # s
142} 141}
143 142
144static void 143static void
145ev_x_cb (struct event *ev, int revents) 144ev_x_cb (struct event *ev, int revents)
146{ 145{
147 revents &= EV_READ | EV_WRITE | EV_TIMEOUT | EV_SIGNAL; 146 revents &= EV_READ | EV_WRITE | EV_TIMER | EV_SIGNAL;
148 147
149 ev->ev_res = revents; 148 ev->ev_res = revents;
150 ev->ev_callback (ev->ev_fd, (short)revents, ev->ev_arg); 149 ev->ev_callback (ev->ev_fd, (short)revents, ev->ev_arg);
151} 150}
152 151
300 if (ev->ev_events & EV_TIMEOUT || ev_is_active (&ev->to) || ev_is_pending (&ev->to)) 299 if (ev->ev_events & EV_TIMEOUT || ev_is_active (&ev->to) || ev_is_pending (&ev->to))
301 { 300 {
302 revents |= EV_TIMEOUT; 301 revents |= EV_TIMEOUT;
303 302
304 if (tv) 303 if (tv)
305 ev_tv_set (tv, ev_now (EV_A)); /* not sure if this is right :) */ 304 EV_TV_SET (tv, ev_now (EV_A)); /* not sure if this is right :) */
306 } 305 }
307 306
308 return events & revents; 307 return events & revents;
309} 308}
310 309
329 328
330int event_base_loop (struct event_base *base, int flags) 329int event_base_loop (struct event_base *base, int flags)
331{ 330{
332 dLOOPbase; 331 dLOOPbase;
333 332
334 ev_loop (EV_A_ flags); 333 ev_run (EV_A_ flags);
335 334
336 return 0; 335 return 0;
337} 336}
338 337
339int event_base_dispatch (struct event_base *base) 338int event_base_dispatch (struct event_base *base)
344static void 343static void
345ev_x_loopexit_cb (int revents, void *base) 344ev_x_loopexit_cb (int revents, void *base)
346{ 345{
347 dLOOPbase; 346 dLOOPbase;
348 347
349 ev_unloop (EV_A_ EVUNLOOP_ONE); 348 ev_break (EV_A_ EVBREAK_ONE);
350} 349}
351 350
352int event_base_loopexit (struct event_base *base, struct timeval *tv) 351int event_base_loopexit (struct event_base *base, struct timeval *tv)
353{ 352{
354 ev_tstamp after = ev_tv_get (tv); 353 ev_tstamp after = ev_tv_get (tv);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines