… | |
… | |
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.3'; |
195 | our $VERSION = '2.31'; |
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); |
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 |