… | |
… | |
190 | use strict 'vars'; |
190 | use strict 'vars'; |
191 | |
191 | |
192 | use base 'Exporter'; |
192 | use base 'Exporter'; |
193 | |
193 | |
194 | BEGIN { |
194 | BEGIN { |
195 | our $VERSION = '2.2'; |
195 | our $VERSION = '2.32'; |
196 | |
196 | |
197 | our @AIO_REQ = qw(aio_sendfile aio_read aio_write aio_open aio_close aio_stat |
197 | our @AIO_REQ = qw(aio_sendfile aio_read aio_write aio_open aio_close aio_stat |
198 | aio_lstat aio_unlink aio_rmdir aio_readdir aio_scandir aio_symlink |
198 | aio_lstat aio_unlink aio_rmdir aio_readdir aio_scandir aio_symlink |
199 | aio_readlink aio_fsync aio_fdatasync aio_readahead aio_rename aio_link |
199 | aio_readlink aio_fsync aio_fdatasync aio_readahead aio_rename aio_link |
200 | aio_move aio_copy aio_group aio_nop aio_mknod); |
200 | aio_move aio_copy aio_group aio_nop aio_mknod aio_load aio_rmtree); |
201 | our @EXPORT = (@AIO_REQ, qw(aioreq_pri aioreq_nice aio_block)); |
201 | our @EXPORT = (@AIO_REQ, qw(aioreq_pri aioreq_nice aio_block)); |
202 | our @EXPORT_OK = qw(poll_fileno poll_cb poll_wait flush |
202 | our @EXPORT_OK = qw(poll_fileno poll_cb poll_wait flush |
203 | min_parallel max_parallel max_idle |
203 | min_parallel max_parallel max_idle |
204 | nreqs nready npending nthreads |
204 | nreqs nready npending nthreads |
205 | max_poll_time max_poll_reqs); |
205 | max_poll_time max_poll_reqs); |
… | |
… | |
443 | directory (i.e. opendir + readdir + closedir). The entries will not be |
443 | directory (i.e. opendir + readdir + closedir). The entries will not be |
444 | sorted, and will B<NOT> include the C<.> and C<..> entries. |
444 | sorted, and will B<NOT> include the C<.> and C<..> entries. |
445 | |
445 | |
446 | The callback a single argument which is either C<undef> or an array-ref |
446 | The callback a single argument which is either C<undef> or an array-ref |
447 | with the filenames. |
447 | with the filenames. |
|
|
448 | |
|
|
449 | =item aio_load $path, $data, $callback->($status) |
|
|
450 | |
|
|
451 | This is a composite request that tries to fully load the given file into |
|
|
452 | memory. Status is the same as with aio_read. |
|
|
453 | |
|
|
454 | =cut |
|
|
455 | |
|
|
456 | sub aio_load($$;$) { |
|
|
457 | aio_block { |
|
|
458 | my ($path, undef, $cb) = @_; |
|
|
459 | my $data = \$_[1]; |
|
|
460 | |
|
|
461 | my $pri = aioreq_pri; |
|
|
462 | my $grp = aio_group $cb; |
|
|
463 | |
|
|
464 | aioreq_pri $pri; |
|
|
465 | add $grp aio_open $path, O_RDONLY, 0, sub { |
|
|
466 | my ($fh) = @_ |
|
|
467 | or return $grp->result (-1); |
|
|
468 | |
|
|
469 | aioreq_pri $pri; |
|
|
470 | add $grp aio_read $fh, 0, (-s $fh), $$data, 0, sub { |
|
|
471 | $grp->result ($_[0]); |
|
|
472 | }; |
|
|
473 | }; |
|
|
474 | |
|
|
475 | $grp |
|
|
476 | } |
|
|
477 | } |
448 | |
478 | |
449 | =item aio_copy $srcpath, $dstpath, $callback->($status) |
479 | =item aio_copy $srcpath, $dstpath, $callback->($status) |
450 | |
480 | |
451 | Try to copy the I<file> (directories not supported as either source or |
481 | Try to copy the I<file> (directories not supported as either source or |
452 | destination) from C<$srcpath> to C<$dstpath> and call the callback with |
482 | destination) from C<$srcpath> to C<$dstpath> and call the callback with |
… | |
… | |
604 | as those tend to return 0 or 1 as link counts, which disables the |
634 | as those tend to return 0 or 1 as link counts, which disables the |
605 | directory counting heuristic. |
635 | directory counting heuristic. |
606 | |
636 | |
607 | =cut |
637 | =cut |
608 | |
638 | |
609 | sub aio_scandir($$$) { |
639 | sub aio_scandir($$;$) { |
610 | aio_block { |
640 | aio_block { |
611 | my ($path, $maxreq, $cb) = @_; |
641 | my ($path, $maxreq, $cb) = @_; |
612 | |
642 | |
613 | my $pri = aioreq_pri; |
643 | my $pri = aioreq_pri; |
614 | |
644 | |
… | |
… | |
692 | |
722 | |
693 | $grp |
723 | $grp |
694 | } |
724 | } |
695 | } |
725 | } |
696 | |
726 | |
|
|
727 | =item aio_rmtree $path, $callback->($status) |
|
|
728 | |
|
|
729 | Delete a directory tree starting (and including) C<$path>, return the |
|
|
730 | status of the final C<rmdir> only. This is a composite request that |
|
|
731 | uses C<aio_scandir> to recurse into and rmdir directories, and unlink |
|
|
732 | everything else. |
|
|
733 | |
|
|
734 | =cut |
|
|
735 | |
|
|
736 | sub aio_rmtree; |
|
|
737 | sub aio_rmtree($;$) { |
|
|
738 | aio_block { |
|
|
739 | my ($path, $cb) = @_; |
|
|
740 | |
|
|
741 | my $pri = aioreq_pri; |
|
|
742 | my $grp = aio_group $cb; |
|
|
743 | |
|
|
744 | aioreq_pri $pri; |
|
|
745 | add $grp aio_scandir $path, 0, sub { |
|
|
746 | my ($dirs, $nondirs) = @_; |
|
|
747 | |
|
|
748 | my $dirgrp = aio_group sub { |
|
|
749 | add $grp aio_rmdir $path, sub { |
|
|
750 | $grp->result ($_[0]); |
|
|
751 | }; |
|
|
752 | }; |
|
|
753 | |
|
|
754 | (aioreq_pri $pri), add $dirgrp aio_rmtree "$path/$_" for @$dirs; |
|
|
755 | (aioreq_pri $pri), add $dirgrp aio_unlink "$path/$_" for @$nondirs; |
|
|
756 | |
|
|
757 | add $grp $dirgrp; |
|
|
758 | }; |
|
|
759 | |
|
|
760 | $grp |
|
|
761 | } |
|
|
762 | } |
|
|
763 | |
697 | =item aio_fsync $fh, $callback->($status) |
764 | =item aio_fsync $fh, $callback->($status) |
698 | |
765 | |
699 | Asynchronously call fsync on the given filehandle and call the callback |
766 | Asynchronously call fsync on the given filehandle and call the callback |
700 | with the fsync result code. |
767 | with the fsync result code. |
701 | |
768 | |