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

Comparing EV/EV.xs (file contents):
Revision 1.29 by root, Thu Nov 1 06:48:49 2007 UTC vs.
Revision 1.34 by root, Thu Nov 1 12:11:07 2007 UTC

3#include "XSUB.h" 3#include "XSUB.h"
4 4
5/*#include <netinet/in.h>*/ 5/*#include <netinet/in.h>*/
6 6
7#define TIMEOUT_NONE HUGE_VAL 7#define TIMEOUT_NONE HUGE_VAL
8#define HAVE_EPOLL 1 8#define EV_USE_EPOLL 1
9 9
10#define EV_PROTOTYPES 1 10#define EV_PROTOTYPES 1
11#include "EV/EVAPI.h" 11#include "EV/EVAPI.h"
12 12
13#include "libev/ev.c" 13#include "libev/ev.c"
17static struct EVAPI evapi; 17static struct EVAPI evapi;
18 18
19static HV 19static HV
20 *stash_watcher, 20 *stash_watcher,
21 *stash_io, 21 *stash_io,
22 *stash_time,
23 *stash_timer, 22 *stash_timer,
24 *stash_periodic, 23 *stash_periodic,
25 *stash_signal, 24 *stash_signal,
26 *stash_idle, 25 *stash_idle,
27 *stash_prepare, 26 *stash_prepare,
31static int 30static int
32sv_signum (SV *sig) 31sv_signum (SV *sig)
33{ 32{
34 int signum; 33 int signum;
35 34
36 if (SvIV (sig) > 0) 35 SvGETMAGIC (sig);
37 return SvIV (sig);
38 36
39 for (signum = 1; signum < SIG_SIZE; ++signum) 37 for (signum = 1; signum < SIG_SIZE; ++signum)
40 if (strEQ (SvPV_nolen (sig), PL_sig_name [signum])) 38 if (strEQ (SvPV_nolen (sig), PL_sig_name [signum]))
41 return signum; 39 return signum;
42 40
41 if (SvIV (sig) > 0)
42 return SvIV (sig);
43
43 return -1; 44 return -1;
44} 45}
45 46
46///////////////////////////////////////////////////////////////////////////// 47/////////////////////////////////////////////////////////////////////////////
47// Event 48// Event
57 fh = SvRV (fh); 58 fh = SvRV (fh);
58 59
59 if (SvTYPE (fh) == SVt_PVGV) 60 if (SvTYPE (fh) == SVt_PVGV)
60 return PerlIO_fileno (IoIFP (sv_2io (fh))); 61 return PerlIO_fileno (IoIFP (sv_2io (fh)));
61 62
62 if (SvIOK (fh)) 63 if ((SvIV (fh) >= 0) && (SvIV (fh) < 0x7ffffff))
63 return SvIV (fh); 64 return SvIV (fh);
64 65
65 return -1; 66 return -1;
66} 67}
67 68
80 w->fh = 0; 81 w->fh = 0;
81 w->cb_sv = newSVsv (cb_sv); 82 w->cb_sv = newSVsv (cb_sv);
82 w->self = self; 83 w->self = self;
83 84
84 return (void *)w; 85 return (void *)w;
86}
87
88static void *
89e_destroy (void *w_)
90{
91 struct ev_watcher *w = w_;
92
93 SvREFCNT_dec (w->fh ); w->fh = 0;
94 SvREFCNT_dec (w->cb_sv); w->cb_sv = 0;
85} 95}
86 96
87static SV * 97static SV *
88e_bless (struct ev_watcher *w, HV *stash) 98e_bless (struct ev_watcher *w, HV *stash)
89{ 99{
203#endif 213#endif
204 214
205#define CHECK_REPEAT(repeat) if (repeat < 0.) \ 215#define CHECK_REPEAT(repeat) if (repeat < 0.) \
206 croak (# repeat " value must be >= 0"); 216 croak (# repeat " value must be >= 0");
207 217
218#define CHECK_FD(fh,fd) if ((fd) < 0) \
219 croak ("illegal file descriptor or filehandle (either no attached file descriptor or illegal value): %s", SvPV_nolen (fh));
220
208///////////////////////////////////////////////////////////////////////////// 221/////////////////////////////////////////////////////////////////////////////
209// XS interface functions 222// XS interface functions
210 223
211MODULE = EV PACKAGE = EV PREFIX = ev_ 224MODULE = EV PACKAGE = EV PREFIX = ev_
212 225
243 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 256 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
244 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 257 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
245 258
246 stash_watcher = gv_stashpv ("EV::Watcher" , 1); 259 stash_watcher = gv_stashpv ("EV::Watcher" , 1);
247 stash_io = gv_stashpv ("EV::Io" , 1); 260 stash_io = gv_stashpv ("EV::Io" , 1);
248 stash_time = gv_stashpv ("EV::Time" , 1);
249 stash_timer = gv_stashpv ("EV::Timer" , 1); 261 stash_timer = gv_stashpv ("EV::Timer" , 1);
250 stash_periodic = gv_stashpv ("EV::Periodic", 1); 262 stash_periodic = gv_stashpv ("EV::Periodic", 1);
251 stash_signal = gv_stashpv ("EV::Signal" , 1); 263 stash_signal = gv_stashpv ("EV::Signal" , 1);
252 stash_idle = gv_stashpv ("EV::Idle" , 1); 264 stash_idle = gv_stashpv ("EV::Idle" , 1);
253 stash_prepare = gv_stashpv ("EV::Prepare" , 1); 265 stash_prepare = gv_stashpv ("EV::Prepare" , 1);
288 evapi.child_stop = ev_child_stop; 300 evapi.child_stop = ev_child_stop;
289 301
290 sv_setiv (sv, (IV)&evapi); 302 sv_setiv (sv, (IV)&evapi);
291 SvREADONLY_on (sv); 303 SvREADONLY_on (sv);
292 } 304 }
305
306 pthread_atfork (ev_fork_prepare, ev_fork_parent, ev_fork_child);
293} 307}
294 308
295NV ev_now () 309NV ev_now ()
296 CODE: 310 CODE:
297 RETVAL = ev_now; 311 RETVAL = ev_now;
316 330
317struct ev_io *io (SV *fh, int events, SV *cb) 331struct ev_io *io (SV *fh, int events, SV *cb)
318 ALIAS: 332 ALIAS:
319 io_ns = 1 333 io_ns = 1
320 CODE: 334 CODE:
335{
336 int fd = sv_fileno (fh);
337 CHECK_FD (fh, fd);
338
321 RETVAL = e_new (sizeof (struct ev_io), cb); 339 RETVAL = e_new (sizeof (struct ev_io), cb);
322 RETVAL->fh = newSVsv (fh); 340 RETVAL->fh = newSVsv (fh);
323 ev_io_set (RETVAL, sv_fileno (RETVAL->fh), events); 341 ev_io_set (RETVAL, fd, events);
324 if (!ix) ev_io_start (RETVAL); 342 if (!ix) ev_io_start (RETVAL);
343}
325 OUTPUT: 344 OUTPUT:
326 RETVAL 345 RETVAL
327 346
328struct ev_timer *timer (NV after, NV repeat, SV *cb) 347struct ev_timer *timer (NV after, NV repeat, SV *cb)
329 ALIAS: 348 ALIAS:
428void ev_io_stop (struct ev_io *w) 447void ev_io_stop (struct ev_io *w)
429 448
430void DESTROY (struct ev_io *w) 449void DESTROY (struct ev_io *w)
431 CODE: 450 CODE:
432 ev_io_stop (w); 451 ev_io_stop (w);
452 e_destroy (w);
433 453
434void set (struct ev_io *w, SV *fh, int events) 454void set (struct ev_io *w, SV *fh, int events)
435 CODE: 455 CODE:
436{ 456{
437 int active = w->active; 457 int active = w->active;
458 int fd = sv_fileno (fh);
459 CHECK_FD (fh, fd);
460
438 if (active) ev_io_stop (w); 461 if (active) ev_io_stop (w);
439 462
440 sv_setsv (w->fh, fh); 463 sv_setsv (w->fh, fh);
441 ev_io_set (w, sv_fileno (w->fh), events); 464 ev_io_set (w, fd, events);
442 465
443 if (active) ev_io_start (w); 466 if (active) ev_io_start (w);
444} 467}
445 468
446SV *fh (struct ev_io *w, SV *new_fh = 0) 469SV *fh (struct ev_io *w, SV *new_fh = 0)
487void ev_signal_stop (struct ev_signal *w) 510void ev_signal_stop (struct ev_signal *w)
488 511
489void DESTROY (struct ev_signal *w) 512void DESTROY (struct ev_signal *w)
490 CODE: 513 CODE:
491 ev_signal_stop (w); 514 ev_signal_stop (w);
515 e_destroy (w);
492 516
493void set (struct ev_signal *w, SV *signal = 0) 517void set (struct ev_signal *w, SV *signal = 0)
494 CODE: 518 CODE:
495{ 519{
496 Signal signum = sv_signum (signal); /* may croak here */ 520 Signal signum = sv_signum (signal); /* may croak here */
516 CHECK_REPEAT (w->repeat); 540 CHECK_REPEAT (w->repeat);
517 541
518void DESTROY (struct ev_timer *w) 542void DESTROY (struct ev_timer *w)
519 CODE: 543 CODE:
520 ev_timer_stop (w); 544 ev_timer_stop (w);
545 e_destroy (w);
521 546
522void set (struct ev_timer *w, NV after, NV repeat = 0.) 547void set (struct ev_timer *w, NV after, NV repeat = 0.)
523 INIT: 548 INIT:
524 CHECK_REPEAT (repeat); 549 CHECK_REPEAT (repeat);
525 CODE: 550 CODE:
539void ev_periodic_stop (struct ev_periodic *w) 564void ev_periodic_stop (struct ev_periodic *w)
540 565
541void DESTROY (struct ev_periodic *w) 566void DESTROY (struct ev_periodic *w)
542 CODE: 567 CODE:
543 ev_periodic_stop (w); 568 ev_periodic_stop (w);
569 e_destroy (w);
544 570
545void set (struct ev_periodic *w, NV at, NV interval = 0.) 571void set (struct ev_periodic *w, NV at, NV interval = 0.)
546 INIT: 572 INIT:
547 CHECK_REPEAT (interval); 573 CHECK_REPEAT (interval);
548 CODE: 574 CODE:
560void ev_idle_stop (struct ev_idle *w) 586void ev_idle_stop (struct ev_idle *w)
561 587
562void DESTROY (struct ev_idle *w) 588void DESTROY (struct ev_idle *w)
563 CODE: 589 CODE:
564 ev_idle_stop (w); 590 ev_idle_stop (w);
591 e_destroy (w);
565 592
566MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_ 593MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_
567 594
568void ev_prepare_start (struct ev_prepare *w) 595void ev_prepare_start (struct ev_prepare *w)
569 596
570void ev_prepare_stop (struct ev_prepare *w) 597void ev_prepare_stop (struct ev_prepare *w)
571 598
572void DESTROY (struct ev_prepare *w) 599void DESTROY (struct ev_prepare *w)
573 CODE: 600 CODE:
574 ev_prepare_stop (w); 601 ev_prepare_stop (w);
602 e_destroy (w);
575 603
576MODULE = EV PACKAGE = EV::Check PREFIX = ev_check_ 604MODULE = EV PACKAGE = EV::Check PREFIX = ev_check_
577 605
578void ev_check_start (struct ev_check *w) 606void ev_check_start (struct ev_check *w)
579 607
580void ev_check_stop (struct ev_check *w) 608void ev_check_stop (struct ev_check *w)
581 609
582void DESTROY (struct ev_check *w) 610void DESTROY (struct ev_check *w)
583 CODE: 611 CODE:
584 ev_check_stop (w); 612 ev_check_stop (w);
613 e_destroy (w);
585 614
586MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ 615MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_
587 616
588void ev_child_start (struct ev_child *w) 617void ev_child_start (struct ev_child *w)
589 618
590void ev_child_stop (struct ev_child *w) 619void ev_child_stop (struct ev_child *w)
591 620
592void DESTROY (struct ev_child *w) 621void DESTROY (struct ev_child *w)
593 CODE: 622 CODE:
594 ev_child_stop (w); 623 ev_child_stop (w);
624 e_destroy (w);
595 625
596void set (struct ev_child *w, int pid) 626void set (struct ev_child *w, int pid)
597 CODE: 627 CODE:
598{ 628{
599 int active = w->active; 629 int active = w->active;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines