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

Comparing EV/EV.xs (file contents):
Revision 1.10 by root, Mon Oct 29 07:56:03 2007 UTC vs.
Revision 1.11 by root, Mon Oct 29 08:48:07 2007 UTC

23#define EV_NONE 0 23#define EV_NONE 0
24#define EV_UNDEF -1 24#define EV_UNDEF -1
25 25
26#define TIMEOUT_NONE HUGE_VAL 26#define TIMEOUT_NONE HUGE_VAL
27 27
28#include "EV/EVAPI.h"
29
28typedef struct event_base *Base; 30typedef struct event_base *Base;
29typedef int Signal; 31typedef int Signal;
32
33static struct EVAPI evapi;
30 34
31static HV *stash_base, *stash_event; 35static HV *stash_base, *stash_event;
32 36
33static double tv_get (struct timeval *tv) 37static double tv_get (struct timeval *tv)
34{ 38{
53 for (signum = 1; signum < SIG_SIZE; ++signum) 57 for (signum = 1; signum < SIG_SIZE; ++signum)
54 if (strEQ (SvPV_nolen (sig), PL_sig_name [signum])) 58 if (strEQ (SvPV_nolen (sig), PL_sig_name [signum]))
55 return signum; 59 return signum;
56 60
57 return -1; 61 return -1;
62}
63
64static void
65api_once (int fd, short events, double timeout, void (*cb)(int, short, void *), void *arg)
66{
67 if (timeout)
68 {
69 struct timeval tv;
70 tv_set (&tv, timeout);
71 event_once (fd, events, cb, arg, &tv);
72 }
73 else
74 event_once (fd, events, cb, arg, 0);
58} 75}
59 76
60///////////////////////////////////////////////////////////////////////////// 77/////////////////////////////////////////////////////////////////////////////
61// Event 78// Event
62 79
69 unsigned char active; 86 unsigned char active;
70 unsigned char abstime; 87 unsigned char abstime;
71} *Event; 88} *Event;
72 89
73static double 90static double
74e_now () 91e_now (void)
75{ 92{
76 struct timeval tv; 93 struct timeval tv;
77 gettimeofday (&tv, 0); 94 gettimeofday (&tv, 0);
78 95
79 return tv_get (&tv); 96 return tv_get (&tv);
297 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 314 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
298 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 315 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
299 316
300 stash_base = gv_stashpv ("EV::Base" , 1); 317 stash_base = gv_stashpv ("EV::Base" , 1);
301 stash_event = gv_stashpv ("EV::Event", 1); 318 stash_event = gv_stashpv ("EV::Event", 1);
319
320 {
321 SV *sv = perl_get_sv ("EV::API", TRUE);
322 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
323
324 evapi.ver = EV_API_VERSION;
325 evapi.rev = EV_API_REVISION;
326 evapi.now = e_now;
327 evapi.once = api_once;
328
329 sv_setiv (sv, (IV)&evapi);
330 SvREADONLY_on (sv);
331 }
302} 332}
303 333
304double now () 334double now ()
305 CODE: 335 CODE:
306 RETVAL = e_now (); 336 RETVAL = e_now ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines