ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/AIO.pm
(Generate patch)

Comparing IO-AIO/AIO.pm (file contents):
Revision 1.73 by root, Tue Oct 24 16:35:04 2006 UTC vs.
Revision 1.74 by root, Tue Oct 24 17:22:17 2006 UTC

520 map [$_, sprintf "%s%04d", (/.\./ ? "1" : "0"), length], 520 map [$_, sprintf "%s%04d", (/.\./ ? "1" : "0"), length],
521 @$entries]; 521 @$entries];
522 522
523 my (@dirs, @nondirs); 523 my (@dirs, @nondirs);
524 524
525 my ($statcb, $schedcb);
526 my $nreq = 0;
527
528 my $statgrp = add $grp aio_group; 525 my $statgrp = add $grp aio_group sub {
526 $grp->result (\@dirs, \@nondirs);
527 };
529 528
530 $schedcb = sub { 529 limit $statgrp $maxreq;
531 if (@$entries) { 530 feed $statgrp sub {
532 if ($nreq < $maxreq) { 531 return unless @$entries;
533 my $ent = pop @$entries; 532 my $entry = pop @$entries;
533
534 add $statgrp aio_stat "$path/$entry/.", sub {
535 if ($_[0] < 0) {
536 push @nondirs, $entry;
537 } else {
538 # need to check for real directory
539 add $statgrp aio_lstat "$path/$entry", sub {
540 if (-d _) {
541 push @dirs, $entry;
542
543 if (!--$ndirs) {
544 push @nondirs, @$entries;
545 $statgrp->cancel_subs;
546 }
547 } else {
548 push @nondirs, $entry;
549 }
534 $nreq++; 550 }
535 add $statgrp aio_stat "$path/$ent/.", sub { $statcb->($_[0], $ent) };
536 } 551 }
537 } elsif (!$nreq) {
538 # finished
539 $statgrp->cancel;
540 undef $statcb;
541 undef $schedcb;
542 $grp->result (\@dirs, \@nondirs);
543 } 552 };
544 }; 553 };
545 $statcb = sub {
546 my ($status, $entry) = @_;
547
548 if ($status < 0) {
549 $nreq--;
550 push @nondirs, $entry;
551 &$schedcb;
552 } else {
553 # need to check for real directory
554 add $grp aio_lstat "$path/$entry", sub {
555 $nreq--;
556
557 if (-d _) {
558 push @dirs, $entry;
559
560 if (!--$ndirs) {
561 push @nondirs, @$entries;
562 $entries = [];
563 }
564 } else {
565 push @nondirs, $entry;
566 }
567
568 &$schedcb;
569 }
570 }
571 };
572
573 &$schedcb while @$entries && $nreq < $maxreq;
574 }; 554 };
575 }; 555 };
576 }; 556 };
577 557
578 $grp 558 $grp
590 570
591If this call isn't available because your OS lacks it or it couldn't be 571If this call isn't available because your OS lacks it or it couldn't be
592detected, it will be emulated by calling C<fsync> instead. 572detected, it will be emulated by calling C<fsync> instead.
593 573
594=item aio_group $callback->(...) 574=item aio_group $callback->(...)
595
596[EXPERIMENTAL]
597 575
598This is a very special aio request: Instead of doing something, it is a 576This is a very special aio request: Instead of doing something, it is a
599container for other aio requests, which is useful if you want to bundle 577container for other aio requests, which is useful if you want to bundle
600many requests into a single, composite, request with a definite callback 578many requests into a single, composite, request with a definite callback
601and the ability to cancel the whole request with its subrequests. 579and the ability to cancel the whole request with its subrequests.
732be added, including other groups, as long as you do not create circular 710be added, including other groups, as long as you do not create circular
733dependencies. 711dependencies.
734 712
735Returns all its arguments. 713Returns all its arguments.
736 714
715=item $grp->cancel_subs
716
717Cancel all subrequests and clears any feeder, but not the group request
718itself. Useful when you queued a lot of events but got a result early.
719
737=item $grp->result (...) 720=item $grp->result (...)
738 721
739Set the result value(s) that will be passed to the group callback when all 722Set the result value(s) that will be passed to the group callback when all
740subrequests have finished. By default, no argument will be passed. 723subrequests have finished. By default, no argument will be passed.
741 724
742=item feed $grp $callback->($grp) 725=item feed $grp $callback->($grp)
743
744[VERY EXPERIMENTAL]
745 726
746Sets a feeder/generator on this group: every group can have an attached 727Sets a feeder/generator on this group: every group can have an attached
747generator that generates requests if idle. The idea behind this is that, 728generator that generates requests if idle. The idea behind this is that,
748although you could just queue as many requests as you want in a group, 729although you could just queue as many requests as you want in a group,
749this might starve other requests for a potentially long time. For 730this might starve other requests for a potentially long time. For

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines