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

Comparing EV/EV.xs (file contents):
Revision 1.140 by root, Thu Apr 22 11:25:43 2010 UTC vs.
Revision 1.151 by root, Thu Dec 30 07:28:47 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
207 208
208 if (expect_true (sv_events_cache)) 209 if (expect_true (sv_events_cache))
209 { 210 {
210 sv_events = sv_events_cache; sv_events_cache = 0; 211 sv_events = sv_events_cache; sv_events_cache = 0;
211 SvIV_set (sv_events, revents); 212 SvIV_set (sv_events, revents);
213 SvIOK_only (sv_events);
212 } 214 }
213 else 215 else
214 { 216 {
215 sv_events = newSViv (revents); 217 sv_events = newSViv (revents);
216 SvREADONLY_on (sv_events); 218 SvREADONLY_on (sv_events);
340 croak ("illegal file descriptor or filehandle (either no attached file descriptor or illegal value): %s", SvPV_nolen (fh)); 342 croak ("illegal file descriptor or filehandle (either no attached file descriptor or illegal value): %s", SvPV_nolen (fh));
341 343
342#define CHECK_SIG(sv,num) if ((num) < 0) \ 344#define CHECK_SIG(sv,num) if ((num) < 0) \
343 croak ("illegal signal number or name: %s", SvPV_nolen (sv)); 345 croak ("illegal signal number or name: %s", SvPV_nolen (sv));
344 346
347static void
348default_fork (void)
349{
350 ev_loop_fork (EV_DEFAULT_UC);
351}
352
345///////////////////////////////////////////////////////////////////////////// 353/////////////////////////////////////////////////////////////////////////////
346// XS interface functions 354// XS interface functions
347 355
348MODULE = EV PACKAGE = EV PREFIX = ev_ 356MODULE = EV PACKAGE = EV PREFIX = ev_
349 357
364 const_iv (EV_, UNDEF) 372 const_iv (EV_, UNDEF)
365 const_iv (EV_, NONE) 373 const_iv (EV_, NONE)
366 const_iv (EV_, READ) 374 const_iv (EV_, READ)
367 const_iv (EV_, WRITE) 375 const_iv (EV_, WRITE)
368 const_iv (EV_, IO) 376 const_iv (EV_, IO)
369 const_iv (EV_, TIMEOUT) /* deprecated */
370 const_iv (EV_, TIMER) 377 const_iv (EV_, TIMER)
371 const_iv (EV_, PERIODIC) 378 const_iv (EV_, PERIODIC)
372 const_iv (EV_, SIGNAL) 379 const_iv (EV_, SIGNAL)
373 const_iv (EV_, CHILD) 380 const_iv (EV_, CHILD)
374 const_iv (EV_, STAT) 381 const_iv (EV_, STAT)
375 const_iv (EV_, IDLE) 382 const_iv (EV_, IDLE)
376 const_iv (EV_, PREPARE) 383 const_iv (EV_, PREPARE)
377 const_iv (EV_, CHECK) 384 const_iv (EV_, CHECK)
378 const_iv (EV_, EMBED) 385 const_iv (EV_, EMBED)
379 const_iv (EV_, FORK) 386 const_iv (EV_, FORK)
387 const_iv (EV_, CLEANUP)
380 const_iv (EV_, ASYNC) 388 const_iv (EV_, ASYNC)
381 const_iv (EV_, CUSTOM) 389 const_iv (EV_, CUSTOM)
382 const_iv (EV_, ERROR) 390 const_iv (EV_, ERROR)
383 391
384 const_iv (EV, LOOP_NONBLOCK)
385 const_iv (EV, LOOP_ONESHOT)
386
387 const_iv (EV, UNLOOP_CANCEL) 392 const_iv (EV, RUN_NOWAIT)
388 const_iv (EV, UNLOOP_ONE) 393 const_iv (EV, RUN_ONCE)
394
395 const_iv (EV, BREAK_CANCEL)
396 const_iv (EV, BREAK_ONE)
389 const_iv (EV, UNLOOP_ALL) 397 const_iv (EV, BREAK_ALL)
390
391 const_iv (EV, BACKEND_SELECT) 398 const_iv (EV, BACKEND_SELECT)
392 const_iv (EV, BACKEND_POLL) 399 const_iv (EV, BACKEND_POLL)
393 const_iv (EV, BACKEND_EPOLL) 400 const_iv (EV, BACKEND_EPOLL)
394 const_iv (EV, BACKEND_KQUEUE) 401 const_iv (EV, BACKEND_KQUEUE)
395 const_iv (EV, BACKEND_DEVPOLL) 402 const_iv (EV, BACKEND_DEVPOLL)
397 const_iv (EV, BACKEND_ALL) 404 const_iv (EV, BACKEND_ALL)
398 const_iv (EV, FLAG_AUTO) 405 const_iv (EV, FLAG_AUTO)
399 const_iv (EV, FLAG_FORKCHECK) 406 const_iv (EV, FLAG_FORKCHECK)
400 const_iv (EV, FLAG_SIGNALFD) 407 const_iv (EV, FLAG_SIGNALFD)
401 const_iv (EV, FLAG_NOENV) 408 const_iv (EV, FLAG_NOENV)
402 const_iv (EV, FLAG_NOSIGFD) /* compatibility, always 0 */
403 const_iv (EV, FLAG_NOINOTIFY) 409 const_iv (EV, FLAG_NOINOTIFY)
404 410
405 const_iv (EV_, VERSION_MAJOR) 411 const_iv (EV_, VERSION_MAJOR)
406 const_iv (EV_, VERSION_MINOR) 412 const_iv (EV_, VERSION_MINOR)
413#if EV_COMPAT3
414 const_iv (EV, FLAG_NOSIGFD) /* compatibility, always 0 */
415 const_iv (EV_, TIMEOUT)
416 const_iv (EV, LOOP_NONBLOCK)
417 const_iv (EV, LOOP_ONESHOT)
418 const_iv (EV, UNLOOP_CANCEL)
419 const_iv (EV, UNLOOP_ONE)
420 const_iv (EV, UNLOOP_ALL)
421#endif
407 }; 422 };
408 423
409 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 424 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
410 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 425 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
411 426
420 stash_check = gv_stashpv ("EV::Check" , 1); 435 stash_check = gv_stashpv ("EV::Check" , 1);
421 stash_child = gv_stashpv ("EV::Child" , 1); 436 stash_child = gv_stashpv ("EV::Child" , 1);
422 stash_embed = gv_stashpv ("EV::Embed" , 1); 437 stash_embed = gv_stashpv ("EV::Embed" , 1);
423 stash_stat = gv_stashpv ("EV::Stat" , 1); 438 stash_stat = gv_stashpv ("EV::Stat" , 1);
424 stash_fork = gv_stashpv ("EV::Fork" , 1); 439 stash_fork = gv_stashpv ("EV::Fork" , 1);
440 stash_cleanup = gv_stashpv ("EV::Cleanup" , 1);
425 stash_async = gv_stashpv ("EV::Async" , 1); 441 stash_async = gv_stashpv ("EV::Async" , 1);
426 442
427 { 443 {
428 SV *sv = perl_get_sv ("EV::API", TRUE); 444 SV *sv = perl_get_sv ("EV::API", TRUE);
429 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ 445 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
448 evapi.now = ev_now; 464 evapi.now = ev_now;
449 evapi.now_update = ev_now_update; 465 evapi.now_update = ev_now_update;
450 evapi.suspend = ev_suspend; 466 evapi.suspend = ev_suspend;
451 evapi.resume = ev_resume; 467 evapi.resume = ev_resume;
452 evapi.backend = ev_backend; 468 evapi.backend = ev_backend;
453 evapi.unloop = ev_unloop; 469 evapi.break_ = ev_break;
454 evapi.invoke_pending = ev_invoke_pending; 470 evapi.invoke_pending = ev_invoke_pending;
455 evapi.pending_count = ev_pending_count; 471 evapi.pending_count = ev_pending_count;
456 evapi.verify = ev_verify; 472 evapi.verify = ev_verify;
457 evapi.set_loop_release_cb = ev_set_loop_release_cb; 473 evapi.set_loop_release_cb = ev_set_loop_release_cb;
458 evapi.set_invoke_pending_cb= ev_set_invoke_pending_cb; 474 evapi.set_invoke_pending_cb= ev_set_invoke_pending_cb;
459 evapi.ref = ev_ref; 475 evapi.ref = ev_ref;
460 evapi.unref = ev_unref; 476 evapi.unref = ev_unref;
461 evapi.loop = ev_loop; 477 evapi.run = ev_run;
462 evapi.once = ev_once; 478 evapi.once = ev_once;
463 evapi.io_start = ev_io_start; 479 evapi.io_start = ev_io_start;
464 evapi.io_stop = ev_io_stop; 480 evapi.io_stop = ev_io_stop;
465 evapi.timer_start = ev_timer_start; 481 evapi.timer_start = ev_timer_start;
466 evapi.timer_stop = ev_timer_stop; 482 evapi.timer_stop = ev_timer_stop;
486 evapi.embed_start = ev_embed_start; 502 evapi.embed_start = ev_embed_start;
487 evapi.embed_stop = ev_embed_stop; 503 evapi.embed_stop = ev_embed_stop;
488 evapi.embed_sweep = ev_embed_sweep; 504 evapi.embed_sweep = ev_embed_sweep;
489 evapi.fork_start = ev_fork_start; 505 evapi.fork_start = ev_fork_start;
490 evapi.fork_stop = ev_fork_stop; 506 evapi.fork_stop = ev_fork_stop;
507 evapi.cleanup_start = ev_cleanup_start;
508 evapi.cleanup_stop = ev_cleanup_stop;
491 evapi.async_start = ev_async_start; 509 evapi.async_start = ev_async_start;
492 evapi.async_stop = ev_async_stop; 510 evapi.async_stop = ev_async_stop;
493 evapi.async_send = ev_async_send; 511 evapi.async_send = ev_async_send;
494 evapi.clear_pending = ev_clear_pending; 512 evapi.clear_pending = ev_clear_pending;
495 evapi.invoke = ev_invoke; 513 evapi.invoke = ev_invoke;
496 514
497 sv_setiv (sv, (IV)&evapi); 515 sv_setiv (sv, (IV)&evapi);
498 SvREADONLY_on (sv); 516 SvREADONLY_on (sv);
499 } 517 }
500#ifndef _WIN32 518#if !defined(_WIN32) && !defined(_MINIX)
501 pthread_atfork (0, 0, ev_default_fork); 519 pthread_atfork (0, 0, default_fork);
502#endif 520#endif
503} 521}
504 522
505SV *ev_default_loop (unsigned int flags = 0) 523SV *ev_default_loop (unsigned int flags = 0)
506 CODE: 524 CODE:
520 OUTPUT: 538 OUTPUT:
521 RETVAL 539 RETVAL
522 540
523void ev_default_destroy () 541void ev_default_destroy ()
524 CODE: 542 CODE:
525 ev_default_destroy (); 543 ev_loop_destroy (EV_DEFAULT_UC);
526 SvREFCNT_dec (default_loop_sv); 544 SvREFCNT_dec (default_loop_sv);
527 default_loop_sv = 0; 545 default_loop_sv = 0;
528 546
529unsigned int ev_supported_backends () 547unsigned int ev_supported_backends ()
530 548
550 568
551unsigned int ev_backend () 569unsigned int ev_backend ()
552 C_ARGS: evapi.default_loop 570 C_ARGS: evapi.default_loop
553 571
554void ev_verify () 572void ev_verify ()
573 ALIAS:
574 loop_verify = 1
555 C_ARGS: evapi.default_loop 575 C_ARGS: evapi.default_loop
556 576
557unsigned int ev_iteration () 577unsigned int ev_iteration ()
578 ALIAS:
579 loop_count = 1
558 C_ARGS: evapi.default_loop 580 C_ARGS: evapi.default_loop
559 581
560unsigned int ev_depth () 582unsigned int ev_depth ()
583 ALIAS:
584 loop_depth = 1
561 C_ARGS: evapi.default_loop 585 C_ARGS: evapi.default_loop
562 586
563void ev_set_io_collect_interval (NV interval) 587void ev_set_io_collect_interval (NV interval)
564 C_ARGS: evapi.default_loop, interval 588 C_ARGS: evapi.default_loop, interval
565 589
566void ev_set_timeout_collect_interval (NV interval) 590void ev_set_timeout_collect_interval (NV interval)
567 C_ARGS: evapi.default_loop, interval 591 C_ARGS: evapi.default_loop, interval
568 592
569void ev_loop (int flags = 0) 593void ev_run (int flags = 0)
594 ALIAS:
595 loop = 1
570 C_ARGS: evapi.default_loop, flags 596 C_ARGS: evapi.default_loop, flags
571 597
572void ev_unloop (int how = EVUNLOOP_ONE) 598void ev_break (int how = EVBREAK_ONE)
599 ALIAS:
600 unloop = 1
573 C_ARGS: evapi.default_loop, how 601 C_ARGS: evapi.default_loop, how
574 602
575void ev_feed_fd_event (int fd, int revents = EV_NONE) 603void ev_feed_fd_event (int fd, int revents = EV_NONE)
576 C_ARGS: evapi.default_loop, fd, revents 604 C_ARGS: evapi.default_loop, fd, revents
577 605
695 ev_fork_set (RETVAL); 723 ev_fork_set (RETVAL);
696 if (!ix) START (fork, RETVAL); 724 if (!ix) START (fork, RETVAL);
697 OUTPUT: 725 OUTPUT:
698 RETVAL 726 RETVAL
699 727
728ev_cleanup *cleanup (SV *cb)
729 ALIAS:
730 cleanup_ns = 1
731 CODE:
732 RETVAL = e_new (sizeof (ev_cleanup), cb, default_loop_sv);
733 ev_cleanup_set (RETVAL);
734 if (!ix) START (cleanup, RETVAL);
735 OUTPUT:
736 RETVAL
700 737
701ev_child *child (int pid, int trace, SV *cb) 738ev_child *child (int pid, int trace, SV *cb)
702 ALIAS: 739 ALIAS:
703 child_ns = 1 740 child_ns = 1
704 CODE: 741 CODE:
722 ev_stat_set (RETVAL, SvPVbyte_nolen (e_fh (RETVAL)), interval); 759 ev_stat_set (RETVAL, SvPVbyte_nolen (e_fh (RETVAL)), interval);
723 if (!ix) START (stat, RETVAL); 760 if (!ix) START (stat, RETVAL);
724 OUTPUT: 761 OUTPUT:
725 RETVAL 762 RETVAL
726 763
764#ifndef EV_NO_LOOPS
765
727ev_embed *embed (struct ev_loop *loop, SV *cb = 0) 766ev_embed *embed (struct ev_loop *loop, SV *cb = 0)
728 ALIAS: 767 ALIAS:
729 embed_ns = 1 768 embed_ns = 1
730 CODE: 769 CODE:
731{ 770{
737 ev_embed_set (RETVAL, loop); 776 ev_embed_set (RETVAL, loop);
738 if (!ix) START (embed, RETVAL); 777 if (!ix) START (embed, RETVAL);
739} 778}
740 OUTPUT: 779 OUTPUT:
741 RETVAL 780 RETVAL
781
782#endif
742 783
743ev_async *async (SV *cb) 784ev_async *async (SV *cb)
744 ALIAS: 785 ALIAS:
745 async_ns = 1 786 async_ns = 1
746 CODE: 787 CODE:
1084 1125
1085void DESTROY (ev_fork *w) 1126void DESTROY (ev_fork *w)
1086 CODE: 1127 CODE:
1087 STOP (fork, w); 1128 STOP (fork, w);
1088 e_destroy (w); 1129 e_destroy (w);
1130
1131MODULE = EV PACKAGE = EV::Cleanup PREFIX = ev_cleanup_
1132
1133void ev_cleanup_start (ev_cleanup *w)
1134 CODE:
1135 START (cleanup, w);
1136
1137void ev_cleanup_stop (ev_cleanup *w)
1138 CODE:
1139 STOP (cleanup, w);
1140
1141void DESTROY (ev_cleanup *w)
1142 CODE:
1143 STOP (cleanup, w);
1144 e_destroy (w);
1145
1146int keepalive (ev_watcher *w, int new_value = 0)
1147 CODE:
1148 RETVAL = 0;
1149 OUTPUT:
1150 RETVAL
1089 1151
1090MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ 1152MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_
1091 1153
1092#if EV_CHILD_ENABLE 1154#if EV_CHILD_ENABLE
1093 1155
1268 CODE: 1330 CODE:
1269 RETVAL = boolSV (ev_async_pending (w)); 1331 RETVAL = boolSV (ev_async_pending (w));
1270 OUTPUT: 1332 OUTPUT:
1271 RETVAL 1333 RETVAL
1272 1334
1335#ifndef EV_NO_LOOPS
1336
1273MODULE = EV PACKAGE = EV::Loop PREFIX = ev_ 1337MODULE = EV PACKAGE = EV::Loop PREFIX = ev_
1274 1338
1275SV *new (SV *klass, unsigned int flags = 0) 1339SV *new (SV *klass, unsigned int flags = 0)
1276 CODE: 1340 CODE:
1277{ 1341{
1285 OUTPUT: 1349 OUTPUT:
1286 RETVAL 1350 RETVAL
1287 1351
1288void DESTROY (struct ev_loop *loop) 1352void DESTROY (struct ev_loop *loop)
1289 CODE: 1353 CODE:
1290 if (loop != evapi.default_loop) /* global destruction sucks */ 1354 /* 1. the default loop shouldn't be freed by destroying it'S pelr loop object */
1355 /* 2. not doing so helps avoid many global destruction bugs in perl, too */
1356 if (loop != evapi.default_loop)
1291 ev_loop_destroy (loop); 1357 ev_loop_destroy (loop);
1292 1358
1293void ev_loop_fork (struct ev_loop *loop) 1359void ev_loop_fork (struct ev_loop *loop)
1294 1360
1361NV ev_now (struct ev_loop *loop)
1362
1363void ev_now_update (struct ev_loop *loop)
1364
1365void ev_suspend (struct ev_loop *loop)
1366
1367void ev_resume (struct ev_loop *loop)
1368
1369void ev_set_io_collect_interval (struct ev_loop *loop, NV interval)
1370
1371void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval)
1372
1373unsigned int ev_backend (struct ev_loop *loop)
1374
1295void ev_verify (struct ev_loop *loop) 1375void ev_verify (struct ev_loop *loop)
1296 1376 ALIAS:
1297NV ev_now (struct ev_loop *loop) 1377 loop_verify = 1
1298
1299void ev_now_update (struct ev_loop *loop)
1300
1301void ev_suspend (struct ev_loop *loop)
1302
1303void ev_resume (struct ev_loop *loop)
1304
1305void ev_set_io_collect_interval (struct ev_loop *loop, NV interval)
1306
1307void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval)
1308
1309unsigned int ev_backend (struct ev_loop *loop)
1310 1378
1311unsigned int ev_iteration (struct ev_loop *loop) 1379unsigned int ev_iteration (struct ev_loop *loop)
1380 ALIAS:
1381 loop_count = 1
1312 1382
1313unsigned int ev_depth (struct ev_loop *loop) 1383unsigned int ev_depth (struct ev_loop *loop)
1384 ALIAS:
1385 loop_depth = 1
1314 1386
1315void ev_loop (struct ev_loop *loop, int flags = 0) 1387void ev_run (struct ev_loop *loop, int flags = 0)
1388 ALIAS:
1389 loop = 1
1316 1390
1317void ev_unloop (struct ev_loop *loop, int how = 1) 1391void ev_break (struct ev_loop *loop, int how = 1)
1392 ALIAS:
1393 unloop = 1
1318 1394
1319void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE) 1395void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE)
1320 1396
1321unsigned int ev_pending_count (struct ev_loop *loop) 1397unsigned int ev_pending_count (struct ev_loop *loop)
1322 1398
1433 ev_fork_set (RETVAL); 1509 ev_fork_set (RETVAL);
1434 if (!ix) START (fork, RETVAL); 1510 if (!ix) START (fork, RETVAL);
1435 OUTPUT: 1511 OUTPUT:
1436 RETVAL 1512 RETVAL
1437 1513
1514ev_cleanup *cleanup (struct ev_loop *loop, SV *cb)
1515 ALIAS:
1516 cleanup_ns = 1
1517 CODE:
1518 RETVAL = e_new (sizeof (ev_cleanup), cb, ST (0));
1519 ev_cleanup_set (RETVAL);
1520 if (!ix) START (cleanup, RETVAL);
1521 OUTPUT:
1522 RETVAL
1438 1523
1439ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb) 1524ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb)
1440 ALIAS: 1525 ALIAS:
1441 child_ns = 1 1526 child_ns = 1
1442 CODE: 1527 CODE:
1495 SvOK (timeout) ? SvNV (timeout) : -1., 1580 SvOK (timeout) ? SvNV (timeout) : -1.,
1496 e_once_cb, 1581 e_once_cb,
1497 newSVsv (cb) 1582 newSVsv (cb)
1498 ); 1583 );
1499 1584
1585#endif
1586

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines