… | |
… | |
193 | use strict 'vars'; |
193 | use strict 'vars'; |
194 | |
194 | |
195 | use base 'Exporter'; |
195 | use base 'Exporter'; |
196 | |
196 | |
197 | BEGIN { |
197 | BEGIN { |
198 | our $VERSION = '3.17'; |
198 | our $VERSION = '3.19'; |
199 | |
199 | |
200 | our @AIO_REQ = qw(aio_sendfile aio_read aio_write aio_open aio_close |
200 | our @AIO_REQ = qw(aio_sendfile aio_read aio_write aio_open aio_close |
201 | aio_stat aio_lstat aio_unlink aio_rmdir aio_readdir |
201 | aio_stat aio_lstat aio_unlink aio_rmdir aio_readdir |
202 | aio_scandir aio_symlink aio_readlink aio_sync aio_fsync |
202 | aio_scandir aio_symlink aio_readlink aio_sync aio_fsync |
203 | aio_fdatasync aio_sync_file_range aio_pathsync aio_readahead |
203 | aio_fdatasync aio_sync_file_range aio_pathsync aio_readahead |
… | |
… | |
338 | |
338 | |
339 | =item aio_read $fh,$offset,$length, $data,$dataoffset, $callback->($retval) |
339 | =item aio_read $fh,$offset,$length, $data,$dataoffset, $callback->($retval) |
340 | |
340 | |
341 | =item aio_write $fh,$offset,$length, $data,$dataoffset, $callback->($retval) |
341 | =item aio_write $fh,$offset,$length, $data,$dataoffset, $callback->($retval) |
342 | |
342 | |
343 | Reads or writes C<$length> bytes from the specified C<$fh> and C<$offset> |
343 | Reads or writes C<$length> bytes from or to the specified C<$fh> and |
344 | into the scalar given by C<$data> and offset C<$dataoffset> and calls the |
344 | C<$offset> into the scalar given by C<$data> and offset C<$dataoffset> |
345 | callback without the actual number of bytes read (or -1 on error, just |
345 | and calls the callback without the actual number of bytes read (or -1 on |
346 | like the syscall). |
346 | error, just like the syscall). |
|
|
347 | |
|
|
348 | C<aio_read> will, like C<sysread>, shrink or grow the C<$data> scalar to |
|
|
349 | offset plus the actual number of bytes read. |
347 | |
350 | |
348 | If C<$offset> is undefined, then the current file descriptor offset will |
351 | If C<$offset> is undefined, then the current file descriptor offset will |
349 | be used (and updated), otherwise the file descriptor offset will not be |
352 | be used (and updated), otherwise the file descriptor offset will not be |
350 | changed by these calls. |
353 | changed by these calls. |
351 | |
354 | |
352 | If C<$length> is undefined in C<aio_write>, use the remaining length of C<$data>. |
355 | If C<$length> is undefined in C<aio_write>, use the remaining length of |
|
|
356 | C<$data>. |
353 | |
357 | |
354 | If C<$dataoffset> is less than zero, it will be counted from the end of |
358 | If C<$dataoffset> is less than zero, it will be counted from the end of |
355 | C<$data>. |
359 | C<$data>. |
356 | |
360 | |
357 | The C<$data> scalar I<MUST NOT> be modified in any way while the request |
361 | The C<$data> scalar I<MUST NOT> be modified in any way while the request |
… | |
… | |
587 | my $grp = aio_group $cb; |
591 | my $grp = aio_group $cb; |
588 | |
592 | |
589 | aioreq_pri $pri; |
593 | aioreq_pri $pri; |
590 | add $grp aio_open $src, O_RDONLY, 0, sub { |
594 | add $grp aio_open $src, O_RDONLY, 0, sub { |
591 | if (my $src_fh = $_[0]) { |
595 | if (my $src_fh = $_[0]) { |
592 | my @stat = stat $src_fh; |
596 | my @stat = stat $src_fh; # hmm, might bock over nfs? |
593 | |
597 | |
594 | aioreq_pri $pri; |
598 | aioreq_pri $pri; |
595 | add $grp aio_open $dst, O_CREAT | O_WRONLY | O_TRUNC, 0200, sub { |
599 | add $grp aio_open $dst, O_CREAT | O_WRONLY | O_TRUNC, 0200, sub { |
596 | if (my $dst_fh = $_[0]) { |
600 | if (my $dst_fh = $_[0]) { |
597 | aioreq_pri $pri; |
601 | aioreq_pri $pri; |
598 | add $grp aio_sendfile $dst_fh, $src_fh, 0, $stat[7], sub { |
602 | add $grp aio_sendfile $dst_fh, $src_fh, 0, $stat[7], sub { |
599 | if ($_[0] == $stat[7]) { |
603 | if ($_[0] == $stat[7]) { |
600 | $grp->result (0); |
604 | $grp->result (0); |
601 | close $src_fh; |
605 | close $src_fh; |
602 | |
606 | |
603 | # those should not normally block. should. should. |
607 | my $ch = sub { |
604 | utime $stat[8], $stat[9], $dst; |
608 | aioreq_pri $pri; |
605 | chmod $stat[2] & 07777, $dst_fh; |
609 | add $grp aio_chmod $dst_fh, $stat[2] & 07777, sub { |
606 | chown $stat[4], $stat[5], $dst_fh; |
610 | aioreq_pri $pri; |
|
|
611 | add $grp aio_chown $dst_fh, $stat[4], $stat[5], sub { |
|
|
612 | aioreq_pri $pri; |
|
|
613 | add $grp aio_close $dst_fh; |
|
|
614 | } |
|
|
615 | }; |
|
|
616 | }; |
607 | |
617 | |
608 | aioreq_pri $pri; |
618 | aioreq_pri $pri; |
609 | add $grp aio_close $dst_fh; |
619 | add $grp aio_utime $dst_fh, $stat[8], $stat[9], sub { |
|
|
620 | if ($_[0] < 0 && $! == ENOSYS) { |
|
|
621 | aioreq_pri $pri; |
|
|
622 | add $grp aio_utime $dst, $stat[8], $stat[9], $ch; |
|
|
623 | } else { |
|
|
624 | $ch->(); |
|
|
625 | } |
|
|
626 | }; |
610 | } else { |
627 | } else { |
611 | $grp->result (-1); |
628 | $grp->result (-1); |
612 | close $src_fh; |
629 | close $src_fh; |
613 | close $dst_fh; |
630 | close $dst_fh; |
614 | |
631 | |