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.191 by root, Thu May 19 23:57:12 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.
692systems that do not deliver the inode information. 701systems that do not deliver the inode information.
693 702
694=item IO::AIO::READDIR_DIRS_FIRST 703=item IO::AIO::READDIR_DIRS_FIRST
695 704
696When this flag is set, then the names will be returned in an order where 705When this flag is set, then the names will be returned in an order where
697likely directories come first. This is useful when you need to quickly 706likely directories come first, in optimal stat order. This is useful when
698find directories, or you want to find all directories while avoiding to 707you need to quickly find directories, or you want to find all directories
699stat() each entry. 708while avoiding to stat() each entry.
700 709
701If the system returns type information in readdir, then this is used 710If the system returns type information in readdir, then this is used
702to find directories directly. Otherwise, likely directories are files 711to find directories directly. Otherwise, likely directories are names
703beginning with ".", or otherwise files with no dots, of which files with 712beginning with ".", or otherwise names with no dots, of which names with
704short names are tried first. 713short names are tried first.
705 714
706=item IO::AIO::READDIR_STAT_ORDER 715=item IO::AIO::READDIR_STAT_ORDER
707 716
708When this flag is set, then the names will be returned in an order 717When this flag is set, then the names will be returned in an order
1417 1426
1418If not all requests were processed for whatever reason, the filehandle 1427If not all requests were processed for whatever reason, the filehandle
1419will still be ready when C<poll_cb> returns, so normally you don't have to 1428will still be ready when C<poll_cb> returns, so normally you don't have to
1420do anything special to have it called later. 1429do anything special to have it called later.
1421 1430
1431Apart from calling C<IO::AIO::poll_cb> when the event filehandle becomes
1432ready, it can be beneficial to call this function from loops which submit
1433a lot of requests, to make sure the results get processed when they become
1434available and not just when the loop is finished and the event loop takes
1435over again. This function returns very fast when there are no outstanding
1436requests.
1437
1422Example: Install an Event watcher that automatically calls 1438Example: Install an Event watcher that automatically calls
1423IO::AIO::poll_cb with high priority (more examples can be found in the 1439IO::AIO::poll_cb with high priority (more examples can be found in the
1424SYNOPSIS section, at the top of this document): 1440SYNOPSIS section, at the top of this document):
1425 1441
1426 Event->io (fd => IO::AIO::poll_fileno, 1442 Event->io (fd => IO::AIO::poll_fileno,
1548Sets the minimum idle timeout (default 10) after which worker threads are 1564Sets the minimum idle timeout (default 10) after which worker threads are
1549allowed to exit. SEe C<IO::AIO::max_idle>. 1565allowed to exit. SEe C<IO::AIO::max_idle>.
1550 1566
1551=item IO::AIO::max_outstanding $maxreqs 1567=item IO::AIO::max_outstanding $maxreqs
1552 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
1553This 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
1554blocks, 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
1555use an C<aio_group> together with a feed callback. 1580use an C<aio_group> together with a feed callback.
1556 1581
1557Sets 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
1558do queue up more than this number of requests, the next call to the 1583a lot of files, you can write somehting like this:
1559C<poll_cb> (and C<poll_some> and other functions calling C<poll_cb>)
1560function will block until the limit is no longer exceeded.
1561 1584
1562The default value is very large, so there is no practical limit on the 1585 IO::AIO::max_outstanding 32;
1563number of outstanding requests.
1564 1586
1565You can still queue as many requests as you want. Therefore, 1587 for my $path (...) {
1566C<max_outstanding> is mainly useful in simple scripts (with low values) or 1588 aio_stat $path , ...;
1567as 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.
1568 1601
1569=back 1602=back
1570 1603
1571=head3 STATISTICAL INFORMATION 1604=head3 STATISTICAL INFORMATION
1572 1605

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines