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.193 by root, Thu May 26 04:15:37 2011 UTC vs.
Revision 1.195 by root, Fri May 27 19:56:31 2011 UTC

168use common::sense; 168use common::sense;
169 169
170use base 'Exporter'; 170use base 'Exporter';
171 171
172BEGIN { 172BEGIN {
173 our $VERSION = '3.8'; 173 our $VERSION = '3.9';
174 174
175 our @AIO_REQ = qw(aio_sendfile aio_read aio_write aio_open aio_close 175 our @AIO_REQ = qw(aio_sendfile aio_read aio_write aio_open aio_close
176 aio_stat aio_lstat aio_unlink aio_rmdir aio_readdir aio_readdirx 176 aio_stat aio_lstat aio_unlink aio_rmdir aio_readdir aio_readdirx
177 aio_scandir aio_symlink aio_readlink aio_sync aio_fsync 177 aio_scandir aio_symlink aio_readlink aio_sync aio_fsync
178 aio_fdatasync aio_sync_file_range aio_pathsync aio_readahead 178 aio_fdatasync aio_sync_file_range aio_pathsync aio_readahead
368 } else { 368 } else {
369 die "open failed: $!\n"; 369 die "open failed: $!\n";
370 } 370 }
371 }; 371 };
372 372
373In addition to all the common open modes/flags (C<O_RDONLY>, C<O_WRONLY>,
374C<O_RDWR>, C<O_CREAT>, C<O_TRUNC>, C<O_EXCL> and C<O_APPEND>), the
375following POSIX and non-POSIX constants are available (missing ones on
376your system are, as usual, C<0>):
377
378C<O_ASYNC>, C<O_DIRECT>, C<O_NOATIME>, C<O_CLOEXEC>, C<O_NOCTTY>, C<O_NOFOLLOW>,
379C<O_NONBLOCK>, C<O_EXEC>, C<O_SEARCH>, C<O_DIRECTORY>, C<O_DSYNC>,
380C<O_RSYNC>, C<O_SYNC> and C<O_TTY_INIT>.
381
373 382
374=item aio_close $fh, $callback->($status) 383=item aio_close $fh, $callback->($status)
375 384
376Asynchronously close a file and call the callback with the result 385Asynchronously close a file and call the callback with the result
377code. 386code.
1555Sets the minimum idle timeout (default 10) after which worker threads are 1564Sets the minimum idle timeout (default 10) after which worker threads are
1556allowed to exit. SEe C<IO::AIO::max_idle>. 1565allowed to exit. SEe C<IO::AIO::max_idle>.
1557 1566
1558=item IO::AIO::max_outstanding $maxreqs 1567=item IO::AIO::max_outstanding $maxreqs
1559 1568
1569Sets the maximum number of outstanding requests to C<$nreqs>. If
1570you do queue up more than this number of requests, the next call to
1571C<IO::AIO::poll_cb> (and other functions calling C<poll_cb>, such as
1572C<IO::AIO::flush> or C<IO::AIO::poll>) will block until the limit is no
1573longer exceeded.
1574
1575In other words, this setting does not enforce a queue limit, but can be
1576used to make poll functions block if the limit is exceeded.
1577
1560This is a very bad function to use in interactive programs because it 1578This is a very bad function to use in interactive programs because it
1561blocks, and a bad way to reduce concurrency because it is inexact: Better 1579blocks, and a bad way to reduce concurrency because it is inexact: Better
1562use an C<aio_group> together with a feed callback. 1580use an C<aio_group> together with a feed callback.
1563 1581
1564Sets the maximum number of outstanding requests to C<$nreqs>. If you 1582It's main use is in scripts without an event loop - when you want to stat
1565do queue up more than this number of requests, the next call to the 1583a lot of files, you can write somehting like this:
1566C<poll_cb> (and C<poll_some> and other functions calling C<poll_cb>)
1567function will block until the limit is no longer exceeded.
1568 1584
1569The default value is very large, so there is no practical limit on the 1585 IO::AIO::max_outstanding 32;
1570number of outstanding requests.
1571 1586
1572You can still queue as many requests as you want. Therefore, 1587 for my $path (...) {
1573C<max_outstanding> is mainly useful in simple scripts (with low values) or 1588 aio_stat $path , ...;
1574as a stop gap to shield against fatal memory overflow (with large values). 1589 IO::AIO::poll_cb;
1590 }
1591
1592 IO::AIO::flush;
1593
1594The call to C<poll_cb> inside the loop will normally return instantly, but
1595as soon as more thna C<32> reqeusts are in-flight, it will block until
1596some requests have been handled. This keeps the loop from pushing a large
1597number of C<aio_stat> requests onto the queue.
1598
1599The default value for C<max_outstanding> is very large, so there is no
1600practical limit on the number of outstanding requests.
1575 1601
1576=back 1602=back
1577 1603
1578=head3 STATISTICAL INFORMATION 1604=head3 STATISTICAL INFORMATION
1579 1605

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines