… | |
… | |
190 | use strict 'vars'; |
190 | use strict 'vars'; |
191 | |
191 | |
192 | use base 'Exporter'; |
192 | use base 'Exporter'; |
193 | |
193 | |
194 | BEGIN { |
194 | BEGIN { |
195 | our $VERSION = '2.32'; |
195 | our $VERSION = '2.33'; |
196 | |
196 | |
197 | our @AIO_REQ = qw(aio_sendfile aio_read aio_write aio_open aio_close aio_stat |
197 | our @AIO_REQ = qw(aio_sendfile aio_read aio_write aio_open aio_close aio_stat |
198 | aio_lstat aio_unlink aio_rmdir aio_readdir aio_scandir aio_symlink |
198 | aio_lstat aio_unlink aio_rmdir aio_readdir aio_scandir aio_symlink |
199 | aio_readlink aio_fsync aio_fdatasync aio_readahead aio_rename aio_link |
199 | aio_readlink aio_fsync aio_fdatasync aio_readahead aio_rename aio_link |
200 | aio_move aio_copy aio_group aio_nop aio_mknod aio_load aio_rmtree); |
200 | aio_move aio_copy aio_group aio_nop aio_mknod aio_load aio_rmtree aio_mkdir); |
201 | our @EXPORT = (@AIO_REQ, qw(aioreq_pri aioreq_nice aio_block)); |
201 | our @EXPORT = (@AIO_REQ, qw(aioreq_pri aioreq_nice aio_block)); |
202 | our @EXPORT_OK = qw(poll_fileno poll_cb poll_wait flush |
202 | our @EXPORT_OK = qw(poll_fileno poll_cb poll_wait flush |
203 | min_parallel max_parallel max_idle |
203 | min_parallel max_parallel max_idle |
204 | nreqs nready npending nthreads |
204 | nreqs nready npending nthreads |
205 | max_poll_time max_poll_reqs); |
205 | max_poll_time max_poll_reqs); |
… | |
… | |
290 | list. They are the same as used by C<sysopen>. |
290 | list. They are the same as used by C<sysopen>. |
291 | |
291 | |
292 | Likewise, C<$mode> specifies the mode of the newly created file, if it |
292 | Likewise, C<$mode> specifies the mode of the newly created file, if it |
293 | didn't exist and C<O_CREAT> has been given, just like perl's C<sysopen>, |
293 | didn't exist and C<O_CREAT> has been given, just like perl's C<sysopen>, |
294 | except that it is mandatory (i.e. use C<0> if you don't create new files, |
294 | except that it is mandatory (i.e. use C<0> if you don't create new files, |
295 | and C<0666> or C<0777> if you do). |
295 | and C<0666> or C<0777> if you do). Note that the C<$mode> will be modified |
|
|
296 | by the umask in effect then the request is being executed, so better never |
|
|
297 | change the umask. |
296 | |
298 | |
297 | Example: |
299 | Example: |
298 | |
300 | |
299 | aio_open "/etc/passwd", O_RDONLY, 0, sub { |
301 | aio_open "/etc/passwd", O_RDONLY, 0, sub { |
300 | if ($_[0]) { |
302 | if ($_[0]) { |
… | |
… | |
430 | =item aio_rename $srcpath, $dstpath, $callback->($status) |
432 | =item aio_rename $srcpath, $dstpath, $callback->($status) |
431 | |
433 | |
432 | Asynchronously rename the object at C<$srcpath> to C<$dstpath>, just as |
434 | Asynchronously rename the object at C<$srcpath> to C<$dstpath>, just as |
433 | rename(2) and call the callback with the result code. |
435 | rename(2) and call the callback with the result code. |
434 | |
436 | |
|
|
437 | =item aio_mkdir $pathname, $mode, $callback->($status) |
|
|
438 | |
|
|
439 | Asynchronously mkdir (create) a directory and call the callback with |
|
|
440 | the result code. C<$mode> will be modified by the umask at the time the |
|
|
441 | request is executed, so do not change your umask. |
|
|
442 | |
435 | =item aio_rmdir $pathname, $callback->($status) |
443 | =item aio_rmdir $pathname, $callback->($status) |
436 | |
444 | |
437 | Asynchronously rmdir (delete) a directory and call the callback with the |
445 | Asynchronously rmdir (delete) a directory and call the callback with the |
438 | result code. |
446 | result code. |
439 | |
447 | |
… | |
… | |
461 | my $pri = aioreq_pri; |
469 | my $pri = aioreq_pri; |
462 | my $grp = aio_group $cb; |
470 | my $grp = aio_group $cb; |
463 | |
471 | |
464 | aioreq_pri $pri; |
472 | aioreq_pri $pri; |
465 | add $grp aio_open $path, O_RDONLY, 0, sub { |
473 | add $grp aio_open $path, O_RDONLY, 0, sub { |
466 | my ($fh) = @_ |
474 | my $fh = shift |
467 | or return $grp->result (-1); |
475 | or return $grp->result (-1); |
468 | |
476 | |
469 | aioreq_pri $pri; |
477 | aioreq_pri $pri; |
470 | add $grp aio_read $fh, 0, (-s $fh), $$data, 0, sub { |
478 | add $grp aio_read $fh, 0, (-s $fh), $$data, 0, sub { |
471 | $grp->result ($_[0]); |
479 | $grp->result ($_[0]); |
… | |
… | |
1070 | Strictly equivalent to: |
1078 | Strictly equivalent to: |
1071 | |
1079 | |
1072 | IO::AIO::poll_wait, IO::AIO::poll_cb |
1080 | IO::AIO::poll_wait, IO::AIO::poll_cb |
1073 | while IO::AIO::nreqs; |
1081 | while IO::AIO::nreqs; |
1074 | |
1082 | |
|
|
1083 | =back |
|
|
1084 | |
1075 | =head3 CONTROLLING THE NUMBER OF THREADS |
1085 | =head3 CONTROLLING THE NUMBER OF THREADS |
|
|
1086 | |
|
|
1087 | =over |
1076 | |
1088 | |
1077 | =item IO::AIO::min_parallel $nthreads |
1089 | =item IO::AIO::min_parallel $nthreads |
1078 | |
1090 | |
1079 | Set the minimum number of AIO threads to C<$nthreads>. The current |
1091 | Set the minimum number of AIO threads to C<$nthreads>. The current |
1080 | default is C<8>, which means eight asynchronous operations can execute |
1092 | default is C<8>, which means eight asynchronous operations can execute |
… | |
… | |
1139 | |
1151 | |
1140 | You can still queue as many requests as you want. Therefore, |
1152 | You can still queue as many requests as you want. Therefore, |
1141 | C<max_oustsanding> is mainly useful in simple scripts (with low values) or |
1153 | C<max_oustsanding> is mainly useful in simple scripts (with low values) or |
1142 | as a stop gap to shield against fatal memory overflow (with large values). |
1154 | as a stop gap to shield against fatal memory overflow (with large values). |
1143 | |
1155 | |
|
|
1156 | =back |
|
|
1157 | |
1144 | =head3 STATISTICAL INFORMATION |
1158 | =head3 STATISTICAL INFORMATION |
|
|
1159 | |
|
|
1160 | =over |
1145 | |
1161 | |
1146 | =item IO::AIO::nreqs |
1162 | =item IO::AIO::nreqs |
1147 | |
1163 | |
1148 | Returns the number of requests currently in the ready, execute or pending |
1164 | Returns the number of requests currently in the ready, execute or pending |
1149 | states (i.e. for which their callback has not been invoked yet). |
1165 | states (i.e. for which their callback has not been invoked yet). |