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

Comparing EV/EV.xs (file contents):
Revision 1.138 by root, Wed Apr 14 00:17:22 2010 UTC vs.
Revision 1.147 by root, Thu Oct 28 04:59:35 2010 UTC

29# define fd_mask Perl_fd_mask 29# define fd_mask Perl_fd_mask
30#endif 30#endif
31/* due to bugs in OS X we have to use libev/ explicitly here */ 31/* due to bugs in OS X we have to use libev/ explicitly here */
32#include "libev/ev.c" 32#include "libev/ev.c"
33 33
34#ifndef _WIN32 34#if !defined(_WIN32) && !defined(_MINIX)
35# include <pthread.h> 35# include <pthread.h>
36#endif 36#endif
37 37
38#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX (((ev_watcher *)(w))->loop)) 38#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX (((ev_watcher *)(w))->loop))
39#define e_flags(w) ((ev_watcher *)(w))->e_flags 39#define e_flags(w) ((ev_watcher *)(w))->e_flags
120 *stash_idle, 120 *stash_idle,
121 *stash_prepare, 121 *stash_prepare,
122 *stash_check, 122 *stash_check,
123 *stash_embed, 123 *stash_embed,
124 *stash_fork, 124 *stash_fork,
125 *stash_cleanup,
125 *stash_async; 126 *stash_async;
126 127
127///////////////////////////////////////////////////////////////////////////// 128/////////////////////////////////////////////////////////////////////////////
128// Event 129// Event
129 130
340 croak ("illegal file descriptor or filehandle (either no attached file descriptor or illegal value): %s", SvPV_nolen (fh)); 341 croak ("illegal file descriptor or filehandle (either no attached file descriptor or illegal value): %s", SvPV_nolen (fh));
341 342
342#define CHECK_SIG(sv,num) if ((num) < 0) \ 343#define CHECK_SIG(sv,num) if ((num) < 0) \
343 croak ("illegal signal number or name: %s", SvPV_nolen (sv)); 344 croak ("illegal signal number or name: %s", SvPV_nolen (sv));
344 345
346EV_INLINE default_fork (void)
347{
348 ev_loop_fork (EV_DEFAULT_UC);
349}
350
345///////////////////////////////////////////////////////////////////////////// 351/////////////////////////////////////////////////////////////////////////////
346// XS interface functions 352// XS interface functions
347 353
348MODULE = EV PACKAGE = EV PREFIX = ev_ 354MODULE = EV PACKAGE = EV PREFIX = ev_
349 355
364 const_iv (EV_, UNDEF) 370 const_iv (EV_, UNDEF)
365 const_iv (EV_, NONE) 371 const_iv (EV_, NONE)
366 const_iv (EV_, READ) 372 const_iv (EV_, READ)
367 const_iv (EV_, WRITE) 373 const_iv (EV_, WRITE)
368 const_iv (EV_, IO) 374 const_iv (EV_, IO)
369 const_iv (EV_, TIMEOUT) /* deprecated */
370 const_iv (EV_, TIMER) 375 const_iv (EV_, TIMER)
371 const_iv (EV_, PERIODIC) 376 const_iv (EV_, PERIODIC)
372 const_iv (EV_, SIGNAL) 377 const_iv (EV_, SIGNAL)
373 const_iv (EV_, CHILD) 378 const_iv (EV_, CHILD)
374 const_iv (EV_, STAT) 379 const_iv (EV_, STAT)
375 const_iv (EV_, IDLE) 380 const_iv (EV_, IDLE)
376 const_iv (EV_, PREPARE) 381 const_iv (EV_, PREPARE)
377 const_iv (EV_, CHECK) 382 const_iv (EV_, CHECK)
378 const_iv (EV_, EMBED) 383 const_iv (EV_, EMBED)
379 const_iv (EV_, FORK) 384 const_iv (EV_, FORK)
385 const_iv (EV_, CLEANUP)
380 const_iv (EV_, ASYNC) 386 const_iv (EV_, ASYNC)
381 const_iv (EV_, CUSTOM) 387 const_iv (EV_, CUSTOM)
382 const_iv (EV_, ERROR) 388 const_iv (EV_, ERROR)
383 389
384 const_iv (EV, LOOP_NONBLOCK)
385 const_iv (EV, LOOP_ONESHOT)
386
387 const_iv (EV, UNLOOP_CANCEL) 390 const_iv (EV, RUN_NOWAIT)
388 const_iv (EV, UNLOOP_ONE) 391 const_iv (EV, RUN_ONCE)
392
393 const_iv (EV, BREAK_CANCEL)
394 const_iv (EV, BREAK_ONE)
389 const_iv (EV, UNLOOP_ALL) 395 const_iv (EV, BREAK_ALL)
390
391 const_iv (EV, BACKEND_SELECT) 396 const_iv (EV, BACKEND_SELECT)
392 const_iv (EV, BACKEND_POLL) 397 const_iv (EV, BACKEND_POLL)
393 const_iv (EV, BACKEND_EPOLL) 398 const_iv (EV, BACKEND_EPOLL)
394 const_iv (EV, BACKEND_KQUEUE) 399 const_iv (EV, BACKEND_KQUEUE)
395 const_iv (EV, BACKEND_DEVPOLL) 400 const_iv (EV, BACKEND_DEVPOLL)
397 const_iv (EV, BACKEND_ALL) 402 const_iv (EV, BACKEND_ALL)
398 const_iv (EV, FLAG_AUTO) 403 const_iv (EV, FLAG_AUTO)
399 const_iv (EV, FLAG_FORKCHECK) 404 const_iv (EV, FLAG_FORKCHECK)
400 const_iv (EV, FLAG_SIGNALFD) 405 const_iv (EV, FLAG_SIGNALFD)
401 const_iv (EV, FLAG_NOENV) 406 const_iv (EV, FLAG_NOENV)
402 const_iv (EV, FLAG_NOSIGFD) /* compatibility, always 0 */
403 const_iv (EV, FLAG_NOINOTIFY) 407 const_iv (EV, FLAG_NOINOTIFY)
404 408
405 const_iv (EV_, VERSION_MAJOR) 409 const_iv (EV_, VERSION_MAJOR)
406 const_iv (EV_, VERSION_MINOR) 410 const_iv (EV_, VERSION_MINOR)
411#if EV_COMPAT3
412 const_iv (EV, FLAG_NOSIGFD) /* compatibility, always 0 */
413 const_iv (EV_, TIMEOUT)
414 const_iv (EV, LOOP_NONBLOCK)
415 const_iv (EV, LOOP_ONESHOT)
416 const_iv (EV, UNLOOP_CANCEL)
417 const_iv (EV, UNLOOP_ONE)
418 const_iv (EV, UNLOOP_ALL)
419#endif
407 }; 420 };
408 421
409 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 422 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
410 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 423 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
411 424
420 stash_check = gv_stashpv ("EV::Check" , 1); 433 stash_check = gv_stashpv ("EV::Check" , 1);
421 stash_child = gv_stashpv ("EV::Child" , 1); 434 stash_child = gv_stashpv ("EV::Child" , 1);
422 stash_embed = gv_stashpv ("EV::Embed" , 1); 435 stash_embed = gv_stashpv ("EV::Embed" , 1);
423 stash_stat = gv_stashpv ("EV::Stat" , 1); 436 stash_stat = gv_stashpv ("EV::Stat" , 1);
424 stash_fork = gv_stashpv ("EV::Fork" , 1); 437 stash_fork = gv_stashpv ("EV::Fork" , 1);
438 stash_cleanup = gv_stashpv ("EV::Cleanup" , 1);
425 stash_async = gv_stashpv ("EV::Async" , 1); 439 stash_async = gv_stashpv ("EV::Async" , 1);
426 440
427 { 441 {
428 SV *sv = perl_get_sv ("EV::API", TRUE); 442 SV *sv = perl_get_sv ("EV::API", TRUE);
429 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ 443 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
448 evapi.now = ev_now; 462 evapi.now = ev_now;
449 evapi.now_update = ev_now_update; 463 evapi.now_update = ev_now_update;
450 evapi.suspend = ev_suspend; 464 evapi.suspend = ev_suspend;
451 evapi.resume = ev_resume; 465 evapi.resume = ev_resume;
452 evapi.backend = ev_backend; 466 evapi.backend = ev_backend;
453 evapi.unloop = ev_unloop; 467 evapi.break_ = ev_break;
454 evapi.invoke_pending = ev_invoke_pending; 468 evapi.invoke_pending = ev_invoke_pending;
455 evapi.pending_count = ev_pending_count; 469 evapi.pending_count = ev_pending_count;
456 evapi.verify = ev_verify; 470 evapi.verify = ev_verify;
457 evapi.set_loop_release_cb = ev_set_loop_release_cb; 471 evapi.set_loop_release_cb = ev_set_loop_release_cb;
458 evapi.set_invoke_pending_cb= ev_set_invoke_pending_cb; 472 evapi.set_invoke_pending_cb= ev_set_invoke_pending_cb;
459 evapi.ref = ev_ref; 473 evapi.ref = ev_ref;
460 evapi.unref = ev_unref; 474 evapi.unref = ev_unref;
461 evapi.loop = ev_loop; 475 evapi.run = ev_run;
462 evapi.once = ev_once; 476 evapi.once = ev_once;
463 evapi.io_start = ev_io_start; 477 evapi.io_start = ev_io_start;
464 evapi.io_stop = ev_io_stop; 478 evapi.io_stop = ev_io_stop;
465 evapi.timer_start = ev_timer_start; 479 evapi.timer_start = ev_timer_start;
466 evapi.timer_stop = ev_timer_stop; 480 evapi.timer_stop = ev_timer_stop;
474 evapi.idle_stop = ev_idle_stop; 488 evapi.idle_stop = ev_idle_stop;
475 evapi.prepare_start = ev_prepare_start; 489 evapi.prepare_start = ev_prepare_start;
476 evapi.prepare_stop = ev_prepare_stop; 490 evapi.prepare_stop = ev_prepare_stop;
477 evapi.check_start = ev_check_start; 491 evapi.check_start = ev_check_start;
478 evapi.check_stop = ev_check_stop; 492 evapi.check_stop = ev_check_stop;
493#if EV_CHILD_ENABLE
479 evapi.child_start = ev_child_start; 494 evapi.child_start = ev_child_start;
480 evapi.child_stop = ev_child_stop; 495 evapi.child_stop = ev_child_stop;
496#endif
481 evapi.stat_start = ev_stat_start; 497 evapi.stat_start = ev_stat_start;
482 evapi.stat_stop = ev_stat_stop; 498 evapi.stat_stop = ev_stat_stop;
483 evapi.stat_stat = ev_stat_stat; 499 evapi.stat_stat = ev_stat_stat;
484 evapi.embed_start = ev_embed_start; 500 evapi.embed_start = ev_embed_start;
485 evapi.embed_stop = ev_embed_stop; 501 evapi.embed_stop = ev_embed_stop;
486 evapi.embed_sweep = ev_embed_sweep; 502 evapi.embed_sweep = ev_embed_sweep;
487 evapi.fork_start = ev_fork_start; 503 evapi.fork_start = ev_fork_start;
488 evapi.fork_stop = ev_fork_stop; 504 evapi.fork_stop = ev_fork_stop;
505 evapi.cleanup_start = ev_cleanup_start;
506 evapi.cleanup_stop = ev_cleanup_stop;
489 evapi.async_start = ev_async_start; 507 evapi.async_start = ev_async_start;
490 evapi.async_stop = ev_async_stop; 508 evapi.async_stop = ev_async_stop;
491 evapi.async_send = ev_async_send; 509 evapi.async_send = ev_async_send;
492 evapi.clear_pending = ev_clear_pending; 510 evapi.clear_pending = ev_clear_pending;
493 evapi.invoke = ev_invoke; 511 evapi.invoke = ev_invoke;
494 512
495 sv_setiv (sv, (IV)&evapi); 513 sv_setiv (sv, (IV)&evapi);
496 SvREADONLY_on (sv); 514 SvREADONLY_on (sv);
497 } 515 }
498#ifndef _WIN32 516#if !defined(_WIN32) && !defined(_MINIX)
499 pthread_atfork (0, 0, ev_default_fork); 517 pthread_atfork (0, 0, default_fork);
500#endif 518#endif
501} 519}
502 520
503SV *ev_default_loop (unsigned int flags = 0) 521SV *ev_default_loop (unsigned int flags = 0)
504 CODE: 522 CODE:
518 OUTPUT: 536 OUTPUT:
519 RETVAL 537 RETVAL
520 538
521void ev_default_destroy () 539void ev_default_destroy ()
522 CODE: 540 CODE:
523 ev_default_destroy (); 541 ev_loop_destroy (EV_DEFAULT_UC);
524 SvREFCNT_dec (default_loop_sv); 542 SvREFCNT_dec (default_loop_sv);
525 default_loop_sv = 0; 543 default_loop_sv = 0;
526 544
527unsigned int ev_supported_backends () 545unsigned int ev_supported_backends ()
528 546
548 566
549unsigned int ev_backend () 567unsigned int ev_backend ()
550 C_ARGS: evapi.default_loop 568 C_ARGS: evapi.default_loop
551 569
552void ev_verify () 570void ev_verify ()
571 ALIAS:
572 loop_verify = 1
553 C_ARGS: evapi.default_loop 573 C_ARGS: evapi.default_loop
554 574
555unsigned int ev_iteration () 575unsigned int ev_iteration ()
576 ALIAS:
577 loop_count = 1
556 C_ARGS: evapi.default_loop 578 C_ARGS: evapi.default_loop
557 579
558unsigned int ev_depth () 580unsigned int ev_depth ()
581 ALIAS:
582 loop_depth = 1
559 C_ARGS: evapi.default_loop 583 C_ARGS: evapi.default_loop
560 584
561void ev_set_io_collect_interval (NV interval) 585void ev_set_io_collect_interval (NV interval)
562 C_ARGS: evapi.default_loop, interval 586 C_ARGS: evapi.default_loop, interval
563 587
564void ev_set_timeout_collect_interval (NV interval) 588void ev_set_timeout_collect_interval (NV interval)
565 C_ARGS: evapi.default_loop, interval 589 C_ARGS: evapi.default_loop, interval
566 590
567void ev_loop (int flags = 0) 591void ev_run (int flags = 0)
592 ALIAS:
593 loop = 1
568 C_ARGS: evapi.default_loop, flags 594 C_ARGS: evapi.default_loop, flags
569 595
570void ev_unloop (int how = EVUNLOOP_ONE) 596void ev_break (int how = EVBREAK_ONE)
597 ALIAS:
598 unloop = 1
571 C_ARGS: evapi.default_loop, how 599 C_ARGS: evapi.default_loop, how
572 600
573void ev_feed_fd_event (int fd, int revents = EV_NONE) 601void ev_feed_fd_event (int fd, int revents = EV_NONE)
574 C_ARGS: evapi.default_loop, fd, revents 602 C_ARGS: evapi.default_loop, fd, revents
575 603
693 ev_fork_set (RETVAL); 721 ev_fork_set (RETVAL);
694 if (!ix) START (fork, RETVAL); 722 if (!ix) START (fork, RETVAL);
695 OUTPUT: 723 OUTPUT:
696 RETVAL 724 RETVAL
697 725
726ev_cleanup *cleanup (SV *cb)
727 ALIAS:
728 cleanup_ns = 1
729 CODE:
730 RETVAL = e_new (sizeof (ev_cleanup), cb, default_loop_sv);
731 ev_cleanup_set (RETVAL);
732 if (!ix) START (cleanup, RETVAL);
733 OUTPUT:
734 RETVAL
735
698ev_child *child (int pid, int trace, SV *cb) 736ev_child *child (int pid, int trace, SV *cb)
699 ALIAS: 737 ALIAS:
700 child_ns = 1 738 child_ns = 1
701 CODE: 739 CODE:
740#if EV_CHILD_ENABLE
702 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv); 741 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv);
703 ev_child_set (RETVAL, pid, trace); 742 ev_child_set (RETVAL, pid, trace);
704 if (!ix) START (child, RETVAL); 743 if (!ix) START (child, RETVAL);
744#else
745 croak ("EV::child watchers not supported on this platform");
746#endif
705 OUTPUT: 747 OUTPUT:
706 RETVAL 748 RETVAL
749
707 750
708ev_stat *stat (SV *path, NV interval, SV *cb) 751ev_stat *stat (SV *path, NV interval, SV *cb)
709 ALIAS: 752 ALIAS:
710 stat_ns = 1 753 stat_ns = 1
711 CODE: 754 CODE:
1077void DESTROY (ev_fork *w) 1120void DESTROY (ev_fork *w)
1078 CODE: 1121 CODE:
1079 STOP (fork, w); 1122 STOP (fork, w);
1080 e_destroy (w); 1123 e_destroy (w);
1081 1124
1125MODULE = EV PACKAGE = EV::Cleanup PREFIX = ev_cleanup_
1126
1127void ev_cleanup_start (ev_cleanup *w)
1128 CODE:
1129 START (cleanup, w);
1130
1131void ev_cleanup_stop (ev_cleanup *w)
1132 CODE:
1133 STOP (cleanup, w);
1134
1135void DESTROY (ev_cleanup *w)
1136 CODE:
1137 STOP (cleanup, w);
1138 e_destroy (w);
1139
1140int keepalive (ev_watcher *w, int new_value = 0)
1141 CODE:
1142 RETVAL = 0;
1143 OUTPUT:
1144 RETVAL
1145
1082MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ 1146MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_
1147
1148#if EV_CHILD_ENABLE
1083 1149
1084void ev_child_start (ev_child *w) 1150void ev_child_start (ev_child *w)
1085 CODE: 1151 CODE:
1086 START (child, w); 1152 START (child, w);
1087 1153
1106 RETVAL = ix == 0 ? w->pid 1172 RETVAL = ix == 0 ? w->pid
1107 : ix == 1 ? w->rpid 1173 : ix == 1 ? w->rpid
1108 : w->rstatus; 1174 : w->rstatus;
1109 OUTPUT: 1175 OUTPUT:
1110 RETVAL 1176 RETVAL
1177
1178#endif
1111 1179
1112MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_ 1180MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_
1113 1181
1114void ev_stat_start (ev_stat *w) 1182void ev_stat_start (ev_stat *w)
1115 CODE: 1183 CODE:
1273 OUTPUT: 1341 OUTPUT:
1274 RETVAL 1342 RETVAL
1275 1343
1276void DESTROY (struct ev_loop *loop) 1344void DESTROY (struct ev_loop *loop)
1277 CODE: 1345 CODE:
1278 if (loop != evapi.default_loop) /* global destruction sucks */ 1346 /* 1. the default loop shouldn't be freed by destroying it'S pelr loop object */
1347 /* 2. not doing so helps avoid many global destruction bugs in perl, too */
1348 if (loop != evapi.default_loop)
1279 ev_loop_destroy (loop); 1349 ev_loop_destroy (loop);
1280 1350
1281void ev_loop_fork (struct ev_loop *loop) 1351void ev_loop_fork (struct ev_loop *loop)
1282 1352
1353NV ev_now (struct ev_loop *loop)
1354
1355void ev_now_update (struct ev_loop *loop)
1356
1357void ev_suspend (struct ev_loop *loop)
1358
1359void ev_resume (struct ev_loop *loop)
1360
1361void ev_set_io_collect_interval (struct ev_loop *loop, NV interval)
1362
1363void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval)
1364
1365unsigned int ev_backend (struct ev_loop *loop)
1366
1283void ev_verify (struct ev_loop *loop) 1367void ev_verify (struct ev_loop *loop)
1284 1368 ALIAS:
1285NV ev_now (struct ev_loop *loop) 1369 loop_verify = 1
1286
1287void ev_now_update (struct ev_loop *loop)
1288
1289void ev_suspend (struct ev_loop *loop)
1290
1291void ev_resume (struct ev_loop *loop)
1292
1293void ev_set_io_collect_interval (struct ev_loop *loop, NV interval)
1294
1295void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval)
1296
1297unsigned int ev_backend (struct ev_loop *loop)
1298 1370
1299unsigned int ev_iteration (struct ev_loop *loop) 1371unsigned int ev_iteration (struct ev_loop *loop)
1372 ALIAS:
1373 loop_count = 1
1300 1374
1301unsigned int ev_depth (struct ev_loop *loop) 1375unsigned int ev_depth (struct ev_loop *loop)
1376 ALIAS:
1377 loop_depth = 1
1302 1378
1303void ev_loop (struct ev_loop *loop, int flags = 0) 1379void ev_run (struct ev_loop *loop, int flags = 0)
1380 ALIAS:
1381 loop = 1
1304 1382
1305void ev_unloop (struct ev_loop *loop, int how = 1) 1383void ev_break (struct ev_loop *loop, int how = 1)
1384 ALIAS:
1385 unloop = 1
1306 1386
1307void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE) 1387void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE)
1308 1388
1309unsigned int ev_pending_count (struct ev_loop *loop) 1389unsigned int ev_pending_count (struct ev_loop *loop)
1310 1390
1421 ev_fork_set (RETVAL); 1501 ev_fork_set (RETVAL);
1422 if (!ix) START (fork, RETVAL); 1502 if (!ix) START (fork, RETVAL);
1423 OUTPUT: 1503 OUTPUT:
1424 RETVAL 1504 RETVAL
1425 1505
1506ev_cleanup *cleanup (struct ev_loop *loop, SV *cb)
1507 ALIAS:
1508 cleanup_ns = 1
1509 CODE:
1510 RETVAL = e_new (sizeof (ev_cleanup), cb, ST (0));
1511 ev_cleanup_set (RETVAL);
1512 if (!ix) START (cleanup, RETVAL);
1513 OUTPUT:
1514 RETVAL
1515
1426ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb) 1516ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb)
1427 ALIAS: 1517 ALIAS:
1428 child_ns = 1 1518 child_ns = 1
1429 CODE: 1519 CODE:
1520#if EV_CHILD_ENABLE
1430 RETVAL = e_new (sizeof (ev_child), cb, ST (0)); 1521 RETVAL = e_new (sizeof (ev_child), cb, ST (0));
1431 ev_child_set (RETVAL, pid, trace); 1522 ev_child_set (RETVAL, pid, trace);
1432 if (!ix) START (child, RETVAL); 1523 if (!ix) START (child, RETVAL);
1524#else
1525 croak ("EV::child watchers not supported on this platform");
1526#endif
1433 OUTPUT: 1527 OUTPUT:
1434 RETVAL 1528 RETVAL
1435 1529
1436ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb) 1530ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb)
1437 ALIAS: 1531 ALIAS:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines