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.168 by root, Mon Nov 30 22:22:13 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($;$) {
1130=item $grp->cancel_subs 1133=item $grp->cancel_subs
1131 1134
1132Cancel all subrequests and clears any feeder, but not the group request 1135Cancel all subrequests and clears any feeder, but not the group request
1133itself. Useful when you queued a lot of events but got a result early. 1136itself. Useful when you queued a lot of events but got a result early.
1134 1137
1138The group request will finish normally (you cannot add requests to the
1139group).
1140
1135=item $grp->result (...) 1141=item $grp->result (...)
1136 1142
1137Set the result value(s) that will be passed to the group callback when all 1143Set the result value(s) that will be passed to the group callback when all
1138subrequests have finished and set the groups errno to the current value 1144subrequests have finished and set the groups errno to the current value
1139of errno (just like calling C<errno> without an error number). By default, 1145of errno (just like calling C<errno> without an error number). By default,
1391 1397
1392=item IO::AIO::npending 1398=item IO::AIO::npending
1393 1399
1394Returns the number of requests currently in the pending state (executed, 1400Returns the number of requests currently in the pending state (executed,
1395but not yet processed by poll_cb). 1401but not yet processed by poll_cb).
1402
1403=back
1404
1405=head3 MISCELLANEOUS FUNCTIONS
1406
1407IO::AIO implements some functions that might be useful, but are not
1408asynchronous.
1409
1410=over 4
1411
1412=item IO::AIO::sendfile $ofh, $ifh, $offset, $count
1413
1414Calls the C<eio_sendfile_sync> function, which is like C<aio_sendfile>,
1415but is blocking (this makes most sense if you know the input data is
1416likely cached already and the output filehandle is set to non-blocking
1417operations).
1418
1419Returns the number of bytes copied, or C<-1> on error.
1420
1421=item IO::AIO::fadvise $fh, $offset, $len, $advice
1422
1423Simply calls the C<posix_fadvise> function (see it's
1424manpage for details). The following advice constants are
1425avaiable: C<IO::AIO::FADV_NORMAL>, C<IO::AIO::FADV_SEQUENTIAL>,
1426C<IO::AIO::FADV_RANDOM>, C<IO::AIO::FADV_NOREUSE>,
1427C<IO::AIO::FADV_WILLNEED>, C<IO::AIO::FADV_DONTNEED>.
1428
1429On systems that do not implement C<posix_fadvise>, this function returns
1430ENOSYS, otherwise the return value of C<posix_fadvise>.
1396 1431
1397=back 1432=back
1398 1433
1399=cut 1434=cut
1400 1435

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines