… | |
… | |
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.31'; |
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 aio_load); |
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); |
… | |
… | |
634 | 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 |
635 | directory counting heuristic. |
635 | directory counting heuristic. |
636 | |
636 | |
637 | =cut |
637 | =cut |
638 | |
638 | |
639 | sub aio_scandir($$$) { |
639 | sub aio_scandir($$;$) { |
640 | aio_block { |
640 | aio_block { |
641 | my ($path, $maxreq, $cb) = @_; |
641 | my ($path, $maxreq, $cb) = @_; |
642 | |
642 | |
643 | my $pri = aioreq_pri; |
643 | my $pri = aioreq_pri; |
644 | |
644 | |
… | |
… | |
722 | |
722 | |
723 | $grp |
723 | $grp |
724 | } |
724 | } |
725 | } |
725 | } |
726 | |
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 | |
727 | =item aio_fsync $fh, $callback->($status) |
764 | =item aio_fsync $fh, $callback->($status) |
728 | |
765 | |
729 | Asynchronously call fsync on the given filehandle and call the callback |
766 | Asynchronously call fsync on the given filehandle and call the callback |
730 | with the fsync result code. |
767 | with the fsync result code. |
731 | |
768 | |