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

Comparing EV/EV.xs (file contents):
Revision 1.139 by root, Thu Apr 22 11:12:06 2010 UTC vs.
Revision 1.146 by root, Sun Oct 24 20:05:43 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
364 const_iv (EV_, UNDEF) 365 const_iv (EV_, UNDEF)
365 const_iv (EV_, NONE) 366 const_iv (EV_, NONE)
366 const_iv (EV_, READ) 367 const_iv (EV_, READ)
367 const_iv (EV_, WRITE) 368 const_iv (EV_, WRITE)
368 const_iv (EV_, IO) 369 const_iv (EV_, IO)
369 const_iv (EV_, TIMEOUT) /* deprecated */
370 const_iv (EV_, TIMER) 370 const_iv (EV_, TIMEOUT)
371 const_iv (EV_, PERIODIC) 371 const_iv (EV_, PERIODIC)
372 const_iv (EV_, SIGNAL) 372 const_iv (EV_, SIGNAL)
373 const_iv (EV_, CHILD) 373 const_iv (EV_, CHILD)
374 const_iv (EV_, STAT) 374 const_iv (EV_, STAT)
375 const_iv (EV_, IDLE) 375 const_iv (EV_, IDLE)
376 const_iv (EV_, PREPARE) 376 const_iv (EV_, PREPARE)
377 const_iv (EV_, CHECK) 377 const_iv (EV_, CHECK)
378 const_iv (EV_, EMBED) 378 const_iv (EV_, EMBED)
379 const_iv (EV_, FORK) 379 const_iv (EV_, FORK)
380 const_iv (EV_, CLEANUP)
380 const_iv (EV_, ASYNC) 381 const_iv (EV_, ASYNC)
381 const_iv (EV_, CUSTOM) 382 const_iv (EV_, CUSTOM)
382 const_iv (EV_, ERROR) 383 const_iv (EV_, ERROR)
383 384
384 const_iv (EV, LOOP_NONBLOCK)
385 const_iv (EV, LOOP_ONESHOT)
386
387 const_iv (EV, UNLOOP_CANCEL) 385 const_iv (EV, RUN_NOWAIT)
388 const_iv (EV, UNLOOP_ONE) 386 const_iv (EV, RUN_ONCE)
387
388 const_iv (EV, BREAK_CANCEL)
389 const_iv (EV, BREAK_ONE)
389 const_iv (EV, UNLOOP_ALL) 390 const_iv (EV, BREAK_ALL)
390
391 const_iv (EV, BACKEND_SELECT) 391 const_iv (EV, BACKEND_SELECT)
392 const_iv (EV, BACKEND_POLL) 392 const_iv (EV, BACKEND_POLL)
393 const_iv (EV, BACKEND_EPOLL) 393 const_iv (EV, BACKEND_EPOLL)
394 const_iv (EV, BACKEND_KQUEUE) 394 const_iv (EV, BACKEND_KQUEUE)
395 const_iv (EV, BACKEND_DEVPOLL) 395 const_iv (EV, BACKEND_DEVPOLL)
402 const_iv (EV, FLAG_NOSIGFD) /* compatibility, always 0 */ 402 const_iv (EV, FLAG_NOSIGFD) /* compatibility, always 0 */
403 const_iv (EV, FLAG_NOINOTIFY) 403 const_iv (EV, FLAG_NOINOTIFY)
404 404
405 const_iv (EV_, VERSION_MAJOR) 405 const_iv (EV_, VERSION_MAJOR)
406 const_iv (EV_, VERSION_MINOR) 406 const_iv (EV_, VERSION_MINOR)
407#if EV_COMPAT3
408 const_iv (EV_, TIMER)
409
410 const_iv (EV, LOOP_NONBLOCK)
411 const_iv (EV, LOOP_ONESHOT)
412
413 const_iv (EV, UNLOOP_CANCEL)
414 const_iv (EV, UNLOOP_ONE)
415 const_iv (EV, UNLOOP_ALL)
416#endif
407 }; 417 };
408 418
409 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 419 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
410 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 420 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
411 421
420 stash_check = gv_stashpv ("EV::Check" , 1); 430 stash_check = gv_stashpv ("EV::Check" , 1);
421 stash_child = gv_stashpv ("EV::Child" , 1); 431 stash_child = gv_stashpv ("EV::Child" , 1);
422 stash_embed = gv_stashpv ("EV::Embed" , 1); 432 stash_embed = gv_stashpv ("EV::Embed" , 1);
423 stash_stat = gv_stashpv ("EV::Stat" , 1); 433 stash_stat = gv_stashpv ("EV::Stat" , 1);
424 stash_fork = gv_stashpv ("EV::Fork" , 1); 434 stash_fork = gv_stashpv ("EV::Fork" , 1);
435 stash_cleanup = gv_stashpv ("EV::Cleanup" , 1);
425 stash_async = gv_stashpv ("EV::Async" , 1); 436 stash_async = gv_stashpv ("EV::Async" , 1);
426 437
427 { 438 {
428 SV *sv = perl_get_sv ("EV::API", TRUE); 439 SV *sv = perl_get_sv ("EV::API", TRUE);
429 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ 440 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
448 evapi.now = ev_now; 459 evapi.now = ev_now;
449 evapi.now_update = ev_now_update; 460 evapi.now_update = ev_now_update;
450 evapi.suspend = ev_suspend; 461 evapi.suspend = ev_suspend;
451 evapi.resume = ev_resume; 462 evapi.resume = ev_resume;
452 evapi.backend = ev_backend; 463 evapi.backend = ev_backend;
453 evapi.unloop = ev_unloop; 464 evapi.break_ = ev_break;
454 evapi.invoke_pending = ev_invoke_pending; 465 evapi.invoke_pending = ev_invoke_pending;
455 evapi.pending_count = ev_pending_count; 466 evapi.pending_count = ev_pending_count;
456 evapi.verify = ev_verify; 467 evapi.verify = ev_verify;
457 evapi.set_loop_release_cb = ev_set_loop_release_cb; 468 evapi.set_loop_release_cb = ev_set_loop_release_cb;
458 evapi.set_invoke_pending_cb= ev_set_invoke_pending_cb; 469 evapi.set_invoke_pending_cb= ev_set_invoke_pending_cb;
459 evapi.ref = ev_ref; 470 evapi.ref = ev_ref;
460 evapi.unref = ev_unref; 471 evapi.unref = ev_unref;
461 evapi.loop = ev_loop; 472 evapi.run = ev_run;
462 evapi.once = ev_once; 473 evapi.once = ev_once;
463 evapi.io_start = ev_io_start; 474 evapi.io_start = ev_io_start;
464 evapi.io_stop = ev_io_stop; 475 evapi.io_stop = ev_io_stop;
465 evapi.timer_start = ev_timer_start; 476 evapi.timer_start = ev_timer_start;
466 evapi.timer_stop = ev_timer_stop; 477 evapi.timer_stop = ev_timer_stop;
486 evapi.embed_start = ev_embed_start; 497 evapi.embed_start = ev_embed_start;
487 evapi.embed_stop = ev_embed_stop; 498 evapi.embed_stop = ev_embed_stop;
488 evapi.embed_sweep = ev_embed_sweep; 499 evapi.embed_sweep = ev_embed_sweep;
489 evapi.fork_start = ev_fork_start; 500 evapi.fork_start = ev_fork_start;
490 evapi.fork_stop = ev_fork_stop; 501 evapi.fork_stop = ev_fork_stop;
502 evapi.cleanup_start = ev_cleanup_start;
503 evapi.cleanup_stop = ev_cleanup_stop;
491 evapi.async_start = ev_async_start; 504 evapi.async_start = ev_async_start;
492 evapi.async_stop = ev_async_stop; 505 evapi.async_stop = ev_async_stop;
493 evapi.async_send = ev_async_send; 506 evapi.async_send = ev_async_send;
494 evapi.clear_pending = ev_clear_pending; 507 evapi.clear_pending = ev_clear_pending;
495 evapi.invoke = ev_invoke; 508 evapi.invoke = ev_invoke;
496 509
497 sv_setiv (sv, (IV)&evapi); 510 sv_setiv (sv, (IV)&evapi);
498 SvREADONLY_on (sv); 511 SvREADONLY_on (sv);
499 } 512 }
500#ifndef _WIN32 513#if !defined(_WIN32) && !defined(_MINIX)
501 pthread_atfork (0, 0, ev_default_fork); 514 pthread_atfork (0, 0, ev_default_fork);
502#endif 515#endif
503} 516}
504 517
505SV *ev_default_loop (unsigned int flags = 0) 518SV *ev_default_loop (unsigned int flags = 0)
520 OUTPUT: 533 OUTPUT:
521 RETVAL 534 RETVAL
522 535
523void ev_default_destroy () 536void ev_default_destroy ()
524 CODE: 537 CODE:
525 ev_default_destroy (); 538 ev_loop_destroy (EV_DEFAULT_UC);
526 SvREFCNT_dec (default_loop_sv); 539 SvREFCNT_dec (default_loop_sv);
527 default_loop_sv = 0; 540 default_loop_sv = 0;
528 541
529unsigned int ev_supported_backends () 542unsigned int ev_supported_backends ()
530 543
550 563
551unsigned int ev_backend () 564unsigned int ev_backend ()
552 C_ARGS: evapi.default_loop 565 C_ARGS: evapi.default_loop
553 566
554void ev_verify () 567void ev_verify ()
568 ALIAS:
569 loop_verify = 1
555 C_ARGS: evapi.default_loop 570 C_ARGS: evapi.default_loop
556 571
557unsigned int ev_iteration () 572unsigned int ev_iteration ()
573 ALIAS:
574 loop_count = 1
558 C_ARGS: evapi.default_loop 575 C_ARGS: evapi.default_loop
559 576
560unsigned int ev_depth () 577unsigned int ev_depth ()
578 ALIAS:
579 loop_depth = 1
561 C_ARGS: evapi.default_loop 580 C_ARGS: evapi.default_loop
562 581
563void ev_set_io_collect_interval (NV interval) 582void ev_set_io_collect_interval (NV interval)
564 C_ARGS: evapi.default_loop, interval 583 C_ARGS: evapi.default_loop, interval
565 584
566void ev_set_timeout_collect_interval (NV interval) 585void ev_set_timeout_collect_interval (NV interval)
567 C_ARGS: evapi.default_loop, interval 586 C_ARGS: evapi.default_loop, interval
568 587
569void ev_loop (int flags = 0) 588void ev_run (int flags = 0)
589 ALIAS:
590 loop = 1
570 C_ARGS: evapi.default_loop, flags 591 C_ARGS: evapi.default_loop, flags
571 592
572void ev_unloop (int how = EVUNLOOP_ONE) 593void ev_break (int how = EVBREAK_ONE)
594 ALIAS:
595 unloop = 1
573 C_ARGS: evapi.default_loop, how 596 C_ARGS: evapi.default_loop, how
574 597
575void ev_feed_fd_event (int fd, int revents = EV_NONE) 598void ev_feed_fd_event (int fd, int revents = EV_NONE)
576 C_ARGS: evapi.default_loop, fd, revents 599 C_ARGS: evapi.default_loop, fd, revents
577 600
695 ev_fork_set (RETVAL); 718 ev_fork_set (RETVAL);
696 if (!ix) START (fork, RETVAL); 719 if (!ix) START (fork, RETVAL);
697 OUTPUT: 720 OUTPUT:
698 RETVAL 721 RETVAL
699 722
723ev_cleanup *cleanup (SV *cb)
724 ALIAS:
725 cleanup_ns = 1
726 CODE:
727 RETVAL = e_new (sizeof (ev_cleanup), cb, default_loop_sv);
728 ev_cleanup_set (RETVAL);
729 if (!ix) START (cleanup, RETVAL);
730 OUTPUT:
731 RETVAL
732
733ev_child *child (int pid, int trace, SV *cb)
734 ALIAS:
735 child_ns = 1
736 CODE:
700#if EV_CHILD_ENABLE 737#if EV_CHILD_ENABLE
701
702ev_child *child (int pid, int trace, SV *cb)
703 ALIAS:
704 child_ns = 1
705 CODE:
706 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv); 738 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv);
707 ev_child_set (RETVAL, pid, trace); 739 ev_child_set (RETVAL, pid, trace);
708 if (!ix) START (child, RETVAL); 740 if (!ix) START (child, RETVAL);
709 OUTPUT: 741#else
710 RETVAL 742 croak ("EV::child watchers not supported on this platform");
711
712#endif 743#endif
744 OUTPUT:
745 RETVAL
746
713 747
714ev_stat *stat (SV *path, NV interval, SV *cb) 748ev_stat *stat (SV *path, NV interval, SV *cb)
715 ALIAS: 749 ALIAS:
716 stat_ns = 1 750 stat_ns = 1
717 CODE: 751 CODE:
1082 1116
1083void DESTROY (ev_fork *w) 1117void DESTROY (ev_fork *w)
1084 CODE: 1118 CODE:
1085 STOP (fork, w); 1119 STOP (fork, w);
1086 e_destroy (w); 1120 e_destroy (w);
1121
1122MODULE = EV PACKAGE = EV::Cleanup PREFIX = ev_cleanup_
1123
1124void ev_cleanup_start (ev_cleanup *w)
1125 CODE:
1126 START (cleanup, w);
1127
1128void ev_cleanup_stop (ev_cleanup *w)
1129 CODE:
1130 STOP (cleanup, w);
1131
1132void DESTROY (ev_cleanup *w)
1133 CODE:
1134 STOP (cleanup, w);
1135 e_destroy (w);
1136
1137int keepalive (ev_watcher *w, int new_value = 0)
1138 CODE:
1139 RETVAL = 0;
1140 OUTPUT:
1141 RETVAL
1087 1142
1088MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ 1143MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_
1089 1144
1090#if EV_CHILD_ENABLE 1145#if EV_CHILD_ENABLE
1091 1146
1283 OUTPUT: 1338 OUTPUT:
1284 RETVAL 1339 RETVAL
1285 1340
1286void DESTROY (struct ev_loop *loop) 1341void DESTROY (struct ev_loop *loop)
1287 CODE: 1342 CODE:
1288 if (loop != evapi.default_loop) /* global destruction sucks */ 1343 /* 1. the default loop shouldn't be freed by destroying it'S pelr loop object */
1344 /* 2. not doing so helps avoid many global destruction bugs in perl, too */
1345 if (loop != evapi.default_loop)
1289 ev_loop_destroy (loop); 1346 ev_loop_destroy (loop);
1290 1347
1291void ev_loop_fork (struct ev_loop *loop) 1348void ev_loop_fork (struct ev_loop *loop)
1292 1349
1350NV ev_now (struct ev_loop *loop)
1351
1352void ev_now_update (struct ev_loop *loop)
1353
1354void ev_suspend (struct ev_loop *loop)
1355
1356void ev_resume (struct ev_loop *loop)
1357
1358void ev_set_io_collect_interval (struct ev_loop *loop, NV interval)
1359
1360void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval)
1361
1362unsigned int ev_backend (struct ev_loop *loop)
1363
1293void ev_verify (struct ev_loop *loop) 1364void ev_verify (struct ev_loop *loop)
1294 1365 ALIAS:
1295NV ev_now (struct ev_loop *loop) 1366 loop_verify = 1
1296
1297void ev_now_update (struct ev_loop *loop)
1298
1299void ev_suspend (struct ev_loop *loop)
1300
1301void ev_resume (struct ev_loop *loop)
1302
1303void ev_set_io_collect_interval (struct ev_loop *loop, NV interval)
1304
1305void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval)
1306
1307unsigned int ev_backend (struct ev_loop *loop)
1308 1367
1309unsigned int ev_iteration (struct ev_loop *loop) 1368unsigned int ev_iteration (struct ev_loop *loop)
1369 ALIAS:
1370 loop_count = 1
1310 1371
1311unsigned int ev_depth (struct ev_loop *loop) 1372unsigned int ev_depth (struct ev_loop *loop)
1373 ALIAS:
1374 loop_depth = 1
1312 1375
1313void ev_loop (struct ev_loop *loop, int flags = 0) 1376void ev_run (struct ev_loop *loop, int flags = 0)
1377 ALIAS:
1378 loop = 1
1314 1379
1315void ev_unloop (struct ev_loop *loop, int how = 1) 1380void ev_break (struct ev_loop *loop, int how = 1)
1381 ALIAS:
1382 unloop = 1
1316 1383
1317void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE) 1384void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE)
1318 1385
1319unsigned int ev_pending_count (struct ev_loop *loop) 1386unsigned int ev_pending_count (struct ev_loop *loop)
1320 1387
1431 ev_fork_set (RETVAL); 1498 ev_fork_set (RETVAL);
1432 if (!ix) START (fork, RETVAL); 1499 if (!ix) START (fork, RETVAL);
1433 OUTPUT: 1500 OUTPUT:
1434 RETVAL 1501 RETVAL
1435 1502
1503ev_cleanup *cleanup (struct ev_loop *loop, SV *cb)
1504 ALIAS:
1505 cleanup_ns = 1
1506 CODE:
1507 RETVAL = e_new (sizeof (ev_cleanup), cb, ST (0));
1508 ev_cleanup_set (RETVAL);
1509 if (!ix) START (cleanup, RETVAL);
1510 OUTPUT:
1511 RETVAL
1512
1513ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb)
1514 ALIAS:
1515 child_ns = 1
1516 CODE:
1436#if EV_CHILD_ENABLE 1517#if EV_CHILD_ENABLE
1437
1438ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb)
1439 ALIAS:
1440 child_ns = 1
1441 CODE:
1442 RETVAL = e_new (sizeof (ev_child), cb, ST (0)); 1518 RETVAL = e_new (sizeof (ev_child), cb, ST (0));
1443 ev_child_set (RETVAL, pid, trace); 1519 ev_child_set (RETVAL, pid, trace);
1444 if (!ix) START (child, RETVAL); 1520 if (!ix) START (child, RETVAL);
1445 OUTPUT: 1521#else
1446 RETVAL 1522 croak ("EV::child watchers not supported on this platform");
1447
1448#endif 1523#endif
1524 OUTPUT:
1525 RETVAL
1449 1526
1450ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb) 1527ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb)
1451 ALIAS: 1528 ALIAS:
1452 stat_ns = 1 1529 stat_ns = 1
1453 CODE: 1530 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines