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.76 by root, Wed Oct 25 08:20:14 2006 UTC

426with the filenames. 426with the filenames.
427 427
428=item aio_scandir $path, $maxreq, $callback->($dirs, $nondirs) 428=item aio_scandir $path, $maxreq, $callback->($dirs, $nondirs)
429 429
430Scans a directory (similar to C<aio_readdir>) but additionally tries to 430Scans a directory (similar to C<aio_readdir>) but additionally tries to
431separate the entries of directory C<$path> into two sets of names, ones 431efficiently separate the entries of directory C<$path> into two sets of
432you can recurse into (directories or links to them), and ones you cannot 432names, directories you can recurse into (directories), and ones you cannot
433recurse into (everything else). 433recurse into (everything else, including symlinks to directories).
434 434
435C<aio_scandir> is a composite request that creates of many sub requests_ 435C<aio_scandir> is a composite request that creates of many sub requests_
436C<$maxreq> specifies the maximum number of outstanding aio requests that 436C<$maxreq> specifies the maximum number of outstanding aio requests that
437this function generates. If it is C<< <= 0 >>, then a suitable default 437this function generates. If it is C<< <= 0 >>, then a suitable default
438will be chosen (currently 6). 438will be chosen (currently 6).
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 unless (--$ndirs) {
544 push @nondirs, @$entries;
545 feed $statgrp;
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