ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/AIO.pm
(Generate patch)

Comparing IO-AIO/AIO.pm (file contents):
Revision 1.156 by root, Tue Jun 16 23:41:59 2009 UTC vs.
Revision 1.167 by root, Thu Nov 12 01:15:36 2009 UTC

186 186
187package IO::AIO; 187package IO::AIO;
188 188
189use Carp (); 189use Carp ();
190 190
191no warnings; 191use common::sense;
192use strict 'vars';
193 192
194use base 'Exporter'; 193use base 'Exporter';
195 194
196BEGIN { 195BEGIN {
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
206 205
207 our @EXPORT = (@AIO_REQ, qw(aioreq_pri aioreq_nice)); 206 our @EXPORT = (@AIO_REQ, qw(aioreq_pri aioreq_nice));
208 our @EXPORT_OK = qw(poll_fileno poll_cb poll_wait flush 207 our @EXPORT_OK = qw(poll_fileno poll_cb poll_wait flush
209 min_parallel max_parallel max_idle 208 min_parallel max_parallel max_idle
210 nreqs nready npending nthreads 209 nreqs nready npending nthreads
211 max_poll_time max_poll_reqs); 210 max_poll_time max_poll_reqs
211 sendfile fadvise);
212 212
213 push @AIO_REQ, qw(aio_busy); # not exported 213 push @AIO_REQ, qw(aio_busy); # not exported
214 214
215 @IO::AIO::GRP::ISA = 'IO::AIO::REQ'; 215 @IO::AIO::GRP::ISA = 'IO::AIO::REQ';
216 216
634 634
635=item aio_copy $srcpath, $dstpath, $callback->($status) 635=item aio_copy $srcpath, $dstpath, $callback->($status)
636 636
637Try to copy the I<file> (directories not supported as either source or 637Try to copy the I<file> (directories not supported as either source or
638destination) from C<$srcpath> to C<$dstpath> and call the callback with 638destination) from C<$srcpath> to C<$dstpath> and call the callback with
639the C<0> (error) or C<-1> ok. 639a status of C<0> (ok) or C<-1> (error, see C<$!>).
640 640
641This is a composite request that creates the destination file with 641This is a composite request that creates the destination file with
642mode 0200 and copies the contents of the source file into it using 642mode 0200 and copies the contents of the source file into it using
643C<aio_sendfile>, followed by restoring atime, mtime, access mode and 643C<aio_sendfile>, followed by restoring atime, mtime, access mode and
644uid/gid, in that order. 644uid/gid, in that order.
656 my $grp = aio_group $cb; 656 my $grp = aio_group $cb;
657 657
658 aioreq_pri $pri; 658 aioreq_pri $pri;
659 add $grp aio_open $src, O_RDONLY, 0, sub { 659 add $grp aio_open $src, O_RDONLY, 0, sub {
660 if (my $src_fh = $_[0]) { 660 if (my $src_fh = $_[0]) {
661 my @stat = stat $src_fh; # hmm, might bock over nfs? 661 my @stat = stat $src_fh; # hmm, might block over nfs?
662 662
663 aioreq_pri $pri; 663 aioreq_pri $pri;
664 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 {
665 if (my $dst_fh = $_[0]) { 665 if (my $dst_fh = $_[0]) {
666 aioreq_pri $pri; 666 aioreq_pri $pri;
713 713
714=item aio_move $srcpath, $dstpath, $callback->($status) 714=item aio_move $srcpath, $dstpath, $callback->($status)
715 715
716Try to move the I<file> (directories not supported as either source or 716Try to move the I<file> (directories not supported as either source or
717destination) from C<$srcpath> to C<$dstpath> and call the callback with 717destination) from C<$srcpath> to C<$dstpath> and call the callback with
718the C<0> (error) or C<-1> ok. 718a status of C<0> (ok) or C<-1> (error, see C<$!>).
719 719
720This is a composite request that tries to rename(2) the file first; if 720This is a composite request that tries to rename(2) the file first; if
721rename fails with C<EXDEV>, it copies the file with C<aio_copy> and, if 721rename fails with C<EXDEV>, it copies the file with C<aio_copy> and, if
722that is successful, unlinks the C<$srcpath>. 722that is successful, unlinks the C<$srcpath>.
723 723
957(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
958specific effect, but usually it makes sure that directory changes get 958specific effect, but usually it makes sure that directory changes get
959written to disc. It works for anything that can be opened for read-only, 959written to disc. It works for anything that can be opened for read-only,
960not just directories. 960not just directories.
961 961
962Future versions of this function might fall back to other methods when
963C<fsync> on the directory fails (such as calling C<sync>).
964
962Passes C<0> when everything went ok, and C<-1> on error. 965Passes C<0> when everything went ok, and C<-1> on error.
963 966
964=cut 967=cut
965 968
966sub aio_pathsync($;$) { 969sub aio_pathsync($;$) {
1394Returns the number of requests currently in the pending state (executed, 1397Returns the number of requests currently in the pending state (executed,
1395but not yet processed by poll_cb). 1398but not yet processed by poll_cb).
1396 1399
1397=back 1400=back
1398 1401
1402=head3 MISCELLANEOUS FUNCTIONS
1403
1404IO::AIO implements some functions that might be useful, but are not
1405asynchronous.
1406
1407=over 4
1408
1409=item IO::AIO::sendfile $ofh, $ifh, $offset, $count
1410
1411Calls the C<eio_sendfile_sync> function, which is like C<aio_sendfile>,
1412but is blocking (this makes most sense if you know the input data is
1413likely cached already and the output filehandle is set to non-blocking
1414operations).
1415
1416Returns the number of bytes copied, or C<-1> on error.
1417
1418=item IO::AIO::fadvise $fh, $offset, $len, $advice
1419
1420Simply calls the C<posix_fadvise> function (see it's
1421manpage for details). The following advice constants are
1422avaiable: C<IO::AIO::FADV_NORMAL>, C<IO::AIO::FADV_SEQUENTIAL>,
1423C<IO::AIO::FADV_RANDOM>, C<IO::AIO::FADV_NOREUSE>,
1424C<IO::AIO::FADV_WILLNEED>, C<IO::AIO::FADV_DONTNEED>.
1425
1426On systems that do not implement C<posix_fadvise>, this function returns
1427ENOSYS, otherwise the return value of C<posix_fadvise>.
1428
1429=back
1430
1399=cut 1431=cut
1400 1432
1401min_parallel 8; 1433min_parallel 8;
1402 1434
1403END { flush } 1435END { flush }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines