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

Comparing EV/EV.xs (file contents):
Revision 1.17 by root, Wed Oct 31 11:52:11 2007 UTC vs.
Revision 1.21 by root, Wed Oct 31 14:44:35 2007 UTC

1#include "EXTERN.h" 1#include "EXTERN.h"
2#include "perl.h" 2#include "perl.h"
3#include "XSUB.h" 3#include "XSUB.h"
4 4
5#include <math.h>
6#include <netinet/in.h> 5/*#include <netinet/in.h>*/
7 6
8#define TIMEOUT_NONE HUGE_VAL 7#define TIMEOUT_NONE HUGE_VAL
8#define HAVE_EPOLL 0
9 9
10#define EV_COMMON \ 10#define EV_PROTOTYPES 1
11 SV *self; /* contains this struct */ \
12 SV *cb_sv, *fh;
13
14#include "EV/EVAPI.h" 11#include "EV/EVAPI.h"
15 12
16#include "libev/ev.c" 13#include "libev/ev.c"
17 14
18typedef int Signal; 15typedef int Signal;
40 for (signum = 1; signum < SIG_SIZE; ++signum) 37 for (signum = 1; signum < SIG_SIZE; ++signum)
41 if (strEQ (SvPV_nolen (sig), PL_sig_name [signum])) 38 if (strEQ (SvPV_nolen (sig), PL_sig_name [signum]))
42 return signum; 39 return signum;
43 40
44 return -1; 41 return -1;
45}
46
47static void
48api_once (int fd, short events, double timeout, void (*cb)(int, short, void *), void *arg)
49{
50#if 0
51 if (timeout >= 0.)
52 {
53 struct timeval tv;
54 tv_set (&tv, timeout);
55 event_once (fd, events, cb, arg, &tv);
56 }
57 else
58 event_once (fd, events, cb, arg, 0);
59#endif
60} 42}
61 43
62///////////////////////////////////////////////////////////////////////////// 44/////////////////////////////////////////////////////////////////////////////
63// Event 45// Event
64 46
211 193
212 LEAVE; 194 LEAVE;
213} 195}
214#endif 196#endif
215 197
198#define CHECK_REPEAT(repeat) if (repeat < 0.) \
199 croak (# repeat " value must be >= 0");
200
216///////////////////////////////////////////////////////////////////////////// 201/////////////////////////////////////////////////////////////////////////////
217// XS interface functions 202// XS interface functions
218 203
219MODULE = EV PACKAGE = EV PREFIX = ev_ 204MODULE = EV PACKAGE = EV PREFIX = ev_
205
206PROTOTYPES: ENABLE
220 207
221BOOT: 208BOOT:
222{ 209{
223 int i; 210 int i;
224 HV *stash = gv_stashpv ("EV", 1); 211 HV *stash = gv_stashpv ("EV", 1);
226 static const struct { 213 static const struct {
227 const char *name; 214 const char *name;
228 IV iv; 215 IV iv;
229 } *civ, const_iv[] = { 216 } *civ, const_iv[] = {
230# define const_iv(pfx, name) { # name, (IV) pfx ## name }, 217# define const_iv(pfx, name) { # name, (IV) pfx ## name },
218 const_iv (EV_, UNDEF)
231 const_iv (EV_, NONE) 219 const_iv (EV_, NONE)
232 const_iv (EV_, TIMEOUT) 220 const_iv (EV_, TIMEOUT)
233 const_iv (EV_, READ) 221 const_iv (EV_, READ)
234 const_iv (EV_, WRITE) 222 const_iv (EV_, WRITE)
235 const_iv (EV_, SIGNAL) 223 const_iv (EV_, SIGNAL)
236 const_iv (EV_, IDLE) 224 const_iv (EV_, IDLE)
237 const_iv (EV_, CHECK) 225 const_iv (EV_, CHECK)
226 const_iv (EV_, ERROR)
238 227
239 const_iv (EV, LOOP_ONESHOT) 228 const_iv (EV, LOOP_ONESHOT)
240 const_iv (EV, LOOP_NONBLOCK) 229 const_iv (EV, LOOP_NONBLOCK)
241 230
242 const_iv (EV, METHOD_NONE) 231 const_iv (EV, METHOD_NONE)
261 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ 250 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
262 251
263 /* the poor man's shared library emulator */ 252 /* the poor man's shared library emulator */
264 evapi.ver = EV_API_VERSION; 253 evapi.ver = EV_API_VERSION;
265 evapi.rev = EV_API_REVISION; 254 evapi.rev = EV_API_REVISION;
266 evapi.once = api_once;
267 evapi.sv_fileno = sv_fileno; 255 evapi.sv_fileno = sv_fileno;
268 evapi.sv_signum = sv_signum; 256 evapi.sv_signum = sv_signum;
269 evapi.now = &ev_now; 257 evapi.now = &ev_now;
270 evapi.method = &ev_method; 258 evapi.method = &ev_method;
271 evapi.loop_done = &ev_loop_done; 259 evapi.loop_done = &ev_loop_done;
272 evapi.time = ev_time; 260 evapi.time = ev_time;
273 evapi.loop = ev_loop; 261 evapi.loop = ev_loop;
262 evapi.once = ev_once;
274 evapi.io_start = evio_start; 263 evapi.io_start = evio_start;
275 evapi.io_stop = evio_stop; 264 evapi.io_stop = evio_stop;
276 evapi.timer_start = evtimer_start; 265 evapi.timer_start = evtimer_start;
277 evapi.timer_stop = evtimer_stop; 266 evapi.timer_stop = evtimer_stop;
278 evapi.timer_again = evtimer_again; 267 evapi.timer_again = evtimer_again;
324 RETVAL 313 RETVAL
325 314
326struct ev_timer *timer (NV after, NV repeat, SV *cb) 315struct ev_timer *timer (NV after, NV repeat, SV *cb)
327 ALIAS: 316 ALIAS:
328 timer_ns = 1 317 timer_ns = 1
318 INIT:
319 CHECK_REPEAT (repeat);
329 CODE: 320 CODE:
330 RETVAL = e_new (sizeof (struct ev_timer), cb); 321 RETVAL = e_new (sizeof (struct ev_timer), cb);
331 evtimer_set (RETVAL, after, repeat); 322 evtimer_set (RETVAL, after, repeat);
332 if (!ix) evtimer_start (RETVAL); 323 if (!ix) evtimer_start (RETVAL);
333 OUTPUT: 324 OUTPUT:
334 RETVAL 325 RETVAL
335 326
336struct ev_periodic *periodic (NV at, NV interval, SV *cb) 327struct ev_periodic *periodic (NV at, NV interval, SV *cb)
337 ALIAS: 328 ALIAS:
338 periodic_ns = 1 329 periodic_ns = 1
330 INIT:
331 CHECK_REPEAT (interval);
339 CODE: 332 CODE:
340 RETVAL = e_new (sizeof (struct ev_periodic), cb); 333 RETVAL = e_new (sizeof (struct ev_periodic), cb);
341 evperiodic_set (RETVAL, at, interval); 334 evperiodic_set (RETVAL, at, interval);
342 if (!ix) evperiodic_start (RETVAL); 335 if (!ix) evperiodic_start (RETVAL);
343 OUTPUT: 336 OUTPUT:
466MODULE = EV PACKAGE = EV::Time 459MODULE = EV PACKAGE = EV::Time
467 460
468MODULE = EV PACKAGE = EV::Timer PREFIX = evtimer_ 461MODULE = EV PACKAGE = EV::Timer PREFIX = evtimer_
469 462
470void evtimer_start (struct ev_timer *w) 463void evtimer_start (struct ev_timer *w)
464 INIT:
465 CHECK_REPEAT (w->repeat);
471 466
472void evtimer_stop (struct ev_timer *w) 467void evtimer_stop (struct ev_timer *w)
473 468
474void evtimer_again (struct ev_timer *w) 469void evtimer_again (struct ev_timer *w)
470 INIT:
471 CHECK_REPEAT (w->repeat);
475 472
476void set (struct ev_timer *w, NV after, NV repeat = 0.) 473void set (struct ev_timer *w, NV after, NV repeat = 0.)
474 INIT:
475 CHECK_REPEAT (repeat);
477 CODE: 476 CODE:
478{ 477{
479 int active = w->active; 478 int active = w->active;
480 if (active) evtimer_stop (w); 479 if (active) evtimer_stop (w);
481 evtimer_set (w, after, repeat); 480 evtimer_set (w, after, repeat);
483} 482}
484 483
485MODULE = EV PACKAGE = EV::Periodic PREFIX = evperiodic_ 484MODULE = EV PACKAGE = EV::Periodic PREFIX = evperiodic_
486 485
487void evperiodic_start (struct ev_periodic *w) 486void evperiodic_start (struct ev_periodic *w)
487 INIT:
488 CHECK_REPEAT (w->interval);
488 489
489void evperiodic_stop (struct ev_periodic *w) 490void evperiodic_stop (struct ev_periodic *w)
490 491
491void set (struct ev_periodic *w, NV at, NV interval = 0.) 492void set (struct ev_periodic *w, NV at, NV interval = 0.)
493 INIT:
494 CHECK_REPEAT (interval);
492 CODE: 495 CODE:
493{ 496{
494 int active = w->active; 497 int active = w->active;
495 if (active) evperiodic_stop (w); 498 if (active) evperiodic_stop (w);
496 evperiodic_set (w, at, interval); 499 evperiodic_set (w, at, interval);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines