… | |
… | |
186 | |
186 | |
187 | package IO::AIO; |
187 | package IO::AIO; |
188 | |
188 | |
189 | use Carp (); |
189 | use Carp (); |
190 | |
190 | |
191 | no warnings; |
191 | use common::sense; |
192 | use strict 'vars'; |
|
|
193 | |
192 | |
194 | use base 'Exporter'; |
193 | use base 'Exporter'; |
195 | |
194 | |
196 | BEGIN { |
195 | BEGIN { |
197 | our $VERSION = '3.23'; |
196 | our $VERSION = '3.31'; |
198 | |
197 | |
199 | our @AIO_REQ = qw(aio_sendfile aio_read aio_write aio_open aio_close |
198 | our @AIO_REQ = qw(aio_sendfile aio_read aio_write aio_open aio_close |
200 | aio_stat aio_lstat aio_unlink aio_rmdir aio_readdir aio_readdirx |
199 | aio_stat aio_lstat aio_unlink aio_rmdir aio_readdir aio_readdirx |
201 | aio_scandir aio_symlink aio_readlink aio_sync aio_fsync |
200 | aio_scandir aio_symlink aio_readlink aio_sync aio_fsync |
202 | aio_fdatasync aio_sync_file_range aio_pathsync aio_readahead |
201 | aio_fdatasync aio_sync_file_range aio_pathsync aio_readahead |
… | |
… | |
635 | |
634 | |
636 | =item aio_copy $srcpath, $dstpath, $callback->($status) |
635 | =item aio_copy $srcpath, $dstpath, $callback->($status) |
637 | |
636 | |
638 | Try to copy the I<file> (directories not supported as either source or |
637 | Try to copy the I<file> (directories not supported as either source or |
639 | destination) from C<$srcpath> to C<$dstpath> and call the callback with |
638 | destination) from C<$srcpath> to C<$dstpath> and call the callback with |
640 | the C<0> (error) or C<-1> ok. |
639 | a status of C<0> (ok) or C<-1> (error, see C<$!>). |
641 | |
640 | |
642 | This is a composite request that creates the destination file with |
641 | This is a composite request that creates the destination file with |
643 | mode 0200 and copies the contents of the source file into it using |
642 | mode 0200 and copies the contents of the source file into it using |
644 | C<aio_sendfile>, followed by restoring atime, mtime, access mode and |
643 | C<aio_sendfile>, followed by restoring atime, mtime, access mode and |
645 | uid/gid, in that order. |
644 | uid/gid, in that order. |
… | |
… | |
657 | my $grp = aio_group $cb; |
656 | my $grp = aio_group $cb; |
658 | |
657 | |
659 | aioreq_pri $pri; |
658 | aioreq_pri $pri; |
660 | add $grp aio_open $src, O_RDONLY, 0, sub { |
659 | add $grp aio_open $src, O_RDONLY, 0, sub { |
661 | if (my $src_fh = $_[0]) { |
660 | if (my $src_fh = $_[0]) { |
662 | my @stat = stat $src_fh; # hmm, might bock over nfs? |
661 | my @stat = stat $src_fh; # hmm, might block over nfs? |
663 | |
662 | |
664 | aioreq_pri $pri; |
663 | aioreq_pri $pri; |
665 | add $grp aio_open $dst, O_CREAT | O_WRONLY | O_TRUNC, 0200, sub { |
664 | add $grp aio_open $dst, O_CREAT | O_WRONLY | O_TRUNC, 0200, sub { |
666 | if (my $dst_fh = $_[0]) { |
665 | if (my $dst_fh = $_[0]) { |
667 | aioreq_pri $pri; |
666 | aioreq_pri $pri; |
… | |
… | |
714 | |
713 | |
715 | =item aio_move $srcpath, $dstpath, $callback->($status) |
714 | =item aio_move $srcpath, $dstpath, $callback->($status) |
716 | |
715 | |
717 | Try to move the I<file> (directories not supported as either source or |
716 | Try to move the I<file> (directories not supported as either source or |
718 | destination) from C<$srcpath> to C<$dstpath> and call the callback with |
717 | destination) from C<$srcpath> to C<$dstpath> and call the callback with |
719 | the C<0> (error) or C<-1> ok. |
718 | a status of C<0> (ok) or C<-1> (error, see C<$!>). |
720 | |
719 | |
721 | This is a composite request that tries to rename(2) the file first; if |
720 | This is a composite request that tries to rename(2) the file first; if |
722 | rename fails with C<EXDEV>, it copies the file with C<aio_copy> and, if |
721 | rename fails with C<EXDEV>, it copies the file with C<aio_copy> and, if |
723 | that is successful, unlinks the C<$srcpath>. |
722 | that is successful, unlinks the C<$srcpath>. |
724 | |
723 | |
… | |
… | |
958 | (E.g. rename). This might not work on all operating systems or have any |
957 | (E.g. rename). This might not work on all operating systems or have any |
959 | specific effect, but usually it makes sure that directory changes get |
958 | specific effect, but usually it makes sure that directory changes get |
960 | written to disc. It works for anything that can be opened for read-only, |
959 | written to disc. It works for anything that can be opened for read-only, |
961 | not just directories. |
960 | not just directories. |
962 | |
961 | |
|
|
962 | Future versions of this function might fall back to other methods when |
|
|
963 | C<fsync> on the directory fails (such as calling C<sync>). |
|
|
964 | |
963 | Passes C<0> when everything went ok, and C<-1> on error. |
965 | Passes C<0> when everything went ok, and C<-1> on error. |
964 | |
966 | |
965 | =cut |
967 | =cut |
966 | |
968 | |
967 | sub aio_pathsync($;$) { |
969 | sub aio_pathsync($;$) { |