--- IO-AIO/AIO.pm 2006/10/26 14:35:34 1.79 +++ IO-AIO/AIO.pm 2006/10/26 16:28:33 1.80 @@ -136,7 +136,7 @@ aio_group aio_nop); our @EXPORT = (@AIO_REQ, qw(aioreq_pri aioreq_nice)); our @EXPORT_OK = qw(poll_fileno poll_cb poll_wait flush - min_parallel max_parallel nreqs); + min_parallel max_parallel nreqs nready npending); @IO::AIO::GRP::ISA = 'IO::AIO::REQ'; @@ -177,13 +177,16 @@ =over 4 -=item aioreq_pri $pri +=item $prev_pri = aioreq_pri [$pri] -Sets the priority for the next aio request. The default priority -is C<0>, the minimum and maximum priorities are C<-4> and C<4>, -respectively. Requests with higher priority will be serviced first. +Returns the priority value that would be used for the next request and, if +C<$pri> is given, sets the priority for the next aio request. -The priority will be reset to C<0> after each call to one of the C +The default priority is C<0>, the minimum and maximum priorities are C<-4> +and C<4>, respectively. Requests with higher priority will be serviced +first. + +The priority will be reset to C<0> after each call to one of the C functions. Example: open a file with low priority, then read something from it with @@ -285,16 +288,21 @@ sub aio_move($$$) { my ($src, $dst, $cb) = @_; + my $pri = aioreq_pri; my $grp = aio_group $cb; + aioreq_pri $pri; add $grp aio_rename $src, $dst, sub { if ($_[0] && $! == EXDEV) { + aioreq_pri $pri; add $grp aio_open $src, O_RDONLY, 0, sub { if (my $src_fh = $_[0]) { my @stat = stat $src_fh; + aioreq_pri $pri; add $grp aio_open $dst, O_WRONLY, 0200, sub { if (my $dst_fh = $_[0]) { + aioreq_pri $pri; add $grp aio_sendfile $dst_fh, $src_fh, 0, $stat[7], sub { close $src_fh; @@ -304,11 +312,13 @@ chown $stat[4], $stat[5], $dst_fh; close $dst_fh; + aioreq_pri $pri; add $grp aio_unlink $src, sub { $grp->result ($_[0]); }; } else { my $errno = $!; + aioreq_pri $pri; add $grp aio_unlink $dst, sub { $! = $errno; $grp->result (-1); @@ -482,22 +492,27 @@ sub aio_scandir($$$) { my ($path, $maxreq, $cb) = @_; + my $pri = aioreq_pri; + my $grp = aio_group $cb; $maxreq = 6 if $maxreq <= 0; # stat once + aioreq_pri $pri; add $grp aio_stat $path, sub { return $grp->result () if $_[0]; my $now = time; my $hash1 = join ":", (stat _)[0,1,3,7,9]; # read the directory entries + aioreq_pri $pri; add $grp aio_readdir $path, sub { my $entries = shift or return $grp->result (); # stat the dir another time + aioreq_pri $pri; add $grp aio_stat $path, sub { my $hash2 = join ":", (stat _)[0,1,3,7,9]; @@ -531,11 +546,13 @@ return unless @$entries; my $entry = pop @$entries; + aioreq_pri $pri; add $statgrp aio_stat "$path/$entry/.", sub { if ($_[0] < 0) { push @nondirs, $entry; } else { # need to check for real directory + aioreq_pri $pri; add $statgrp aio_lstat "$path/$entry", sub { if (-d _) { push @dirs, $entry; @@ -716,7 +733,21 @@ =item $grp->result (...) Set the result value(s) that will be passed to the group callback when all -subrequests have finished. By default, no argument will be passed. +subrequests have finished and set thre groups errno to the current value +of errno (just like calling C without an error number). By default, +no argument will be passed and errno is zero. + +=item $grp->errno ([$errno]) + +Sets the group errno value to C<$errno>, or the current value of errno +when the argument is missing. + +Every aio request has an associated errno value that is restored when +the callback is invoked. This method lets you change this value from its +default (0). + +Calling C will also set errno, so make sure you either set C<$!> +before the call to C, or call c after it. =item feed $grp $callback->($grp) @@ -818,14 +849,24 @@ =item IO::AIO::nreqs -Returns the number of requests currently outstanding (i.e. for which their -callback has not been invoked yet). +Returns the number of requests currently in the ready, execute or pending +states (i.e. for which their callback has not been invoked yet). Example: wait till there are no outstanding requests anymore: IO::AIO::poll_wait, IO::AIO::poll_cb while IO::AIO::nreqs; +=item IO::AIO::nready + +Returns the number of requests currently in the ready state (not yet +executed). + +=item IO::AIO::npending + +Returns the number of requests currently in the pending state (executed, +but not yet processed by poll_cb). + =item IO::AIO::flush Wait till all outstanding AIO requests have been handled.