… | |
… | |
171 | use common::sense; |
171 | use common::sense; |
172 | |
172 | |
173 | use base 'Exporter'; |
173 | use base 'Exporter'; |
174 | |
174 | |
175 | BEGIN { |
175 | BEGIN { |
176 | our $VERSION = 4.79; |
176 | our $VERSION = 4.81; |
177 | |
177 | |
178 | our @AIO_REQ = qw(aio_sendfile aio_seek aio_read aio_write aio_open aio_close |
178 | our @AIO_REQ = qw(aio_sendfile aio_seek aio_read aio_write aio_open aio_close |
179 | aio_stat aio_lstat aio_unlink aio_rmdir aio_readdir aio_readdirx |
179 | aio_stat aio_lstat aio_unlink aio_rmdir aio_readdir aio_readdirx |
180 | aio_scandir aio_symlink aio_readlink aio_realpath aio_fcntl aio_ioctl |
180 | aio_scandir aio_symlink aio_readlink aio_realpath aio_fcntl aio_ioctl |
181 | aio_sync aio_fsync aio_syncfs aio_fdatasync aio_sync_file_range |
181 | aio_sync aio_fsync aio_syncfs aio_fdatasync aio_sync_file_range |
… | |
… | |
413 | =item aio_open $pathname, $flags, $mode, $callback->($fh) |
413 | =item aio_open $pathname, $flags, $mode, $callback->($fh) |
414 | |
414 | |
415 | Asynchronously open or create a file and call the callback with a newly |
415 | Asynchronously open or create a file and call the callback with a newly |
416 | created filehandle for the file (or C<undef> in case of an error). |
416 | created filehandle for the file (or C<undef> in case of an error). |
417 | |
417 | |
418 | The pathname passed to C<aio_open> must be absolute. See API NOTES, above, |
|
|
419 | for an explanation. |
|
|
420 | |
|
|
421 | The C<$flags> argument is a bitmask. See the C<Fcntl> module for a |
418 | The C<$flags> argument is a bitmask. See the C<Fcntl> module for a |
422 | list. They are the same as used by C<sysopen>. |
419 | list. They are the same as used by C<sysopen>. |
423 | |
420 | |
424 | Likewise, C<$mode> specifies the mode of the newly created file, if it |
421 | Likewise, C<$mode> specifies the mode of the newly created file, if it |
425 | didn't exist and C<O_CREAT> has been given, just like perl's C<sysopen>, |
422 | didn't exist and C<O_CREAT> has been given, just like perl's C<sysopen>, |
… | |
… | |
584 | |
581 | |
585 | Works almost exactly like perl's C<stat> or C<lstat> in void context. The |
582 | Works almost exactly like perl's C<stat> or C<lstat> in void context. The |
586 | callback will be called after the stat and the results will be available |
583 | callback will be called after the stat and the results will be available |
587 | using C<stat _> or C<-s _> and other tests (with the exception of C<-B> |
584 | using C<stat _> or C<-s _> and other tests (with the exception of C<-B> |
588 | and C<-T>). |
585 | and C<-T>). |
589 | |
|
|
590 | The pathname passed to C<aio_stat> must be absolute. See API NOTES, above, |
|
|
591 | for an explanation. |
|
|
592 | |
586 | |
593 | Currently, the stats are always 64-bit-stats, i.e. instead of returning an |
587 | Currently, the stats are always 64-bit-stats, i.e. instead of returning an |
594 | error when stat'ing a large file, the results will be silently truncated |
588 | error when stat'ing a large file, the results will be silently truncated |
595 | unless perl itself is compiled with large file support. |
589 | unless perl itself is compiled with large file support. |
596 | |
590 | |
… | |
… | |
981 | my @stat = stat $src_fh; # hmm, might block over nfs? |
975 | my @stat = stat $src_fh; # hmm, might block over nfs? |
982 | |
976 | |
983 | aioreq_pri $pri; |
977 | aioreq_pri $pri; |
984 | add $grp aio_open $dst, O_CREAT | O_WRONLY | O_TRUNC, 0200, sub { |
978 | add $grp aio_open $dst, O_CREAT | O_WRONLY | O_TRUNC, 0200, sub { |
985 | if (my $dst_fh = $_[0]) { |
979 | if (my $dst_fh = $_[0]) { |
|
|
980 | |
|
|
981 | # best-effort preallocate |
|
|
982 | aioreq_pri $pri; |
|
|
983 | add $grp aio_allocate $dst_fh, IO::AIO::FALLOC_FL_KEEP_SIZE, 0, $stat[7], sub { }; |
|
|
984 | |
986 | aioreq_pri $pri; |
985 | aioreq_pri $pri; |
987 | add $grp aio_sendfile $dst_fh, $src_fh, 0, $stat[7], sub { |
986 | add $grp aio_sendfile $dst_fh, $src_fh, 0, $stat[7], sub { |
988 | if ($_[0] == $stat[7]) { |
987 | if ($_[0] == $stat[7]) { |
989 | $grp->result (0); |
988 | $grp->result (0); |
990 | close $src_fh; |
989 | close $src_fh; |