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.271 by root, Fri Jun 23 21:43:51 2017 UTC vs.
Revision 1.278 by root, Sun Oct 1 07:24:34 2017 UTC

277 IO::AIO::idle_timeout $seconds 277 IO::AIO::idle_timeout $seconds
278 IO::AIO::max_outstanding $maxreqs 278 IO::AIO::max_outstanding $maxreqs
279 IO::AIO::nreqs 279 IO::AIO::nreqs
280 IO::AIO::nready 280 IO::AIO::nready
281 IO::AIO::npending 281 IO::AIO::npending
282 $nfd = IO::AIO::get_fdlimit [EXPERIMENTAL]
283 IO::AIO::min_fdlimit $nfd [EXPERIMENTAL]
282 284
283 IO::AIO::sendfile $ofh, $ifh, $offset, $count 285 IO::AIO::sendfile $ofh, $ifh, $offset, $count
284 IO::AIO::fadvise $fh, $offset, $len, $advice 286 IO::AIO::fadvise $fh, $offset, $len, $advice
285 IO::AIO::mmap $scalar, $length, $prot, $flags[, $fh[, $offset]] 287 IO::AIO::mmap $scalar, $length, $prot, $flags[, $fh[, $offset]]
286 IO::AIO::munmap $scalar 288 IO::AIO::munmap $scalar
740C<$mode> is usually C<0> or C<IO::AIO::FALLOC_FL_KEEP_SIZE> to allocate 742C<$mode> is usually C<0> or C<IO::AIO::FALLOC_FL_KEEP_SIZE> to allocate
741space, or C<IO::AIO::FALLOC_FL_PUNCH_HOLE | IO::AIO::FALLOC_FL_KEEP_SIZE>, 743space, or C<IO::AIO::FALLOC_FL_PUNCH_HOLE | IO::AIO::FALLOC_FL_KEEP_SIZE>,
742to deallocate a file range. 744to deallocate a file range.
743 745
744IO::AIO also supports C<FALLOC_FL_COLLAPSE_RANGE>, to remove a range 746IO::AIO also supports C<FALLOC_FL_COLLAPSE_RANGE>, to remove a range
745(without leaving a hole) and C<FALLOC_FL_ZERO_RANGE>, to zero a range (see 747(without leaving a hole), C<FALLOC_FL_ZERO_RANGE>, to zero a range,
746your L<fallocate(2)> manpage). 748C<FALLOC_FL_INSERT_RANGE> to insert a range and C<FALLOC_FL_UNSHARE_RANGE>
749to unshare shared blocks (see your L<fallocate(2)> manpage).
747 750
748The file system block size used by C<fallocate> is presumably the 751The file system block size used by C<fallocate> is presumably the
749C<f_bsize> returned by C<statvfs>. 752C<f_bsize> returned by C<statvfs>, but different filesystems and filetypes
753can dictate other limitations.
750 754
751If C<fallocate> isn't available or cannot be emulated (currently no 755If C<fallocate> isn't available or cannot be emulated (currently no
752emulation will be attempted), passes C<-1> and sets C<$!> to C<ENOSYS>. 756emulation will be attempted), passes C<-1> and sets C<$!> to C<ENOSYS>.
753 757
754 758
955=item aio_copy $srcpath, $dstpath, $callback->($status) 959=item aio_copy $srcpath, $dstpath, $callback->($status)
956 960
957Try to copy the I<file> (directories not supported as either source or 961Try to copy the I<file> (directories not supported as either source or
958destination) from C<$srcpath> to C<$dstpath> and call the callback with 962destination) from C<$srcpath> to C<$dstpath> and call the callback with
959a status of C<0> (ok) or C<-1> (error, see C<$!>). 963a status of C<0> (ok) or C<-1> (error, see C<$!>).
964
965Existing destination files will be truncated.
960 966
961This is a composite request that creates the destination file with 967This is a composite request that creates the destination file with
962mode 0200 and copies the contents of the source file into it using 968mode 0200 and copies the contents of the source file into it using
963C<aio_sendfile>, followed by restoring atime, mtime, access mode and 969C<aio_sendfile>, followed by restoring atime, mtime, access mode and
964uid/gid, in that order. 970uid/gid, in that order.
1074Scans a directory (similar to C<aio_readdir>) but additionally tries to 1080Scans a directory (similar to C<aio_readdir>) but additionally tries to
1075efficiently separate the entries of directory C<$path> into two sets of 1081efficiently separate the entries of directory C<$path> into two sets of
1076names, directories you can recurse into (directories), and ones you cannot 1082names, directories you can recurse into (directories), and ones you cannot
1077recurse into (everything else, including symlinks to directories). 1083recurse into (everything else, including symlinks to directories).
1078 1084
1079C<aio_scandir> is a composite request that creates of many sub requests_ 1085C<aio_scandir> is a composite request that generates many sub requests.
1080C<$maxreq> specifies the maximum number of outstanding aio requests that 1086C<$maxreq> specifies the maximum number of outstanding aio requests that
1081this function generates. If it is C<< <= 0 >>, then a suitable default 1087this function generates. If it is C<< <= 0 >>, then a suitable default
1082will be chosen (currently 4). 1088will be chosen (currently 4).
1083 1089
1084On error, the callback is called without arguments, otherwise it receives 1090On error, the callback is called without arguments, otherwise it receives
1477C<IO::AIO::FIEMAP_EXTENT_DATA_ENCRYPTED>, C<IO::AIO::FIEMAP_EXTENT_NOT_ALIGNED>, 1483C<IO::AIO::FIEMAP_EXTENT_DATA_ENCRYPTED>, C<IO::AIO::FIEMAP_EXTENT_NOT_ALIGNED>,
1478C<IO::AIO::FIEMAP_EXTENT_DATA_INLINE>, C<IO::AIO::FIEMAP_EXTENT_DATA_TAIL>, 1484C<IO::AIO::FIEMAP_EXTENT_DATA_INLINE>, C<IO::AIO::FIEMAP_EXTENT_DATA_TAIL>,
1479C<IO::AIO::FIEMAP_EXTENT_UNWRITTEN>, C<IO::AIO::FIEMAP_EXTENT_MERGED> or 1485C<IO::AIO::FIEMAP_EXTENT_UNWRITTEN>, C<IO::AIO::FIEMAP_EXTENT_MERGED> or
1480C<IO::AIO::FIEMAP_EXTENT_SHARED>. 1486C<IO::AIO::FIEMAP_EXTENT_SHARED>.
1481 1487
1482At the time of this writing (Linux 3.2), this requets is unreliable unless 1488At the time of this writing (Linux 3.2), this request is unreliable unless
1483C<$count> is C<undef>, as the kernel has all sorts of bugs preventing 1489C<$count> is C<undef>, as the kernel has all sorts of bugs preventing
1484it to return all extents of a range for files with large number of 1490it to return all extents of a range for files with a large number of
1485extents. The code works around all these issues if C<$count> is undef. 1491extents. The code (only) works around all these issues if C<$count> is
1492C<undef>.
1486 1493
1487=item aio_group $callback->(...) 1494=item aio_group $callback->(...)
1488 1495
1489This is a very special aio request: Instead of doing something, it is a 1496This is a very special aio request: Instead of doing something, it is a
1490container for other aio requests, which is useful if you want to bundle 1497container for other aio requests, which is useful if you want to bundle
1603There are some caveats: when directories get renamed (or deleted), the 1610There are some caveats: when directories get renamed (or deleted), the
1604pathname string doesn't change, so will point to the new directory (or 1611pathname string doesn't change, so will point to the new directory (or
1605nowhere at all), while the directory fd, if available on the system, 1612nowhere at all), while the directory fd, if available on the system,
1606will still point to the original directory. Most functions accepting a 1613will still point to the original directory. Most functions accepting a
1607pathname will use the directory fd on newer systems, and the string on 1614pathname will use the directory fd on newer systems, and the string on
1608older systems. Some functions (such as realpath) will always rely on the 1615older systems. Some functions (such as C<aio_realpath>) will always rely on
1609string form of the pathname. 1616the string form of the pathname.
1610 1617
1611So this functionality is mainly useful to get some protection against 1618So this functionality is mainly useful to get some protection against
1612C<chdir>, to easily get an absolute path out of a relative path for future 1619C<chdir>, to easily get an absolute path out of a relative path for future
1613reference, and to speed up doing many operations in the same directory 1620reference, and to speed up doing many operations in the same directory
1614(e.g. when stat'ing all files in a directory). 1621(e.g. when stat'ing all files in a directory).
2006This is a very bad function to use in interactive programs because it 2013This is a very bad function to use in interactive programs because it
2007blocks, and a bad way to reduce concurrency because it is inexact: Better 2014blocks, and a bad way to reduce concurrency because it is inexact: Better
2008use an C<aio_group> together with a feed callback. 2015use an C<aio_group> together with a feed callback.
2009 2016
2010Its main use is in scripts without an event loop - when you want to stat 2017Its main use is in scripts without an event loop - when you want to stat
2011a lot of files, you can write somehting like this: 2018a lot of files, you can write something like this:
2012 2019
2013 IO::AIO::max_outstanding 32; 2020 IO::AIO::max_outstanding 32;
2014 2021
2015 for my $path (...) { 2022 for my $path (...) {
2016 aio_stat $path , ...; 2023 aio_stat $path , ...;
2061some "Advanced I/O" function not available to in Perl, without going the 2068some "Advanced I/O" function not available to in Perl, without going the
2062"Asynchronous I/O" route. Many of these have an asynchronous C<aio_*> 2069"Asynchronous I/O" route. Many of these have an asynchronous C<aio_*>
2063counterpart. 2070counterpart.
2064 2071
2065=over 4 2072=over 4
2073
2074=item $numfd = IO::AIO::get_fdlimit
2075
2076This function is I<EXPERIMENTAL> and subject to change.
2077
2078Tries to find the current file descriptor limit and returns it, or
2079C<undef> and sets C<$!> in case of an error. The limit is one larger than
2080the highest valid file descriptor number.
2081
2082=item IO::AIO::min_fdlimit [$numfd]
2083
2084This function is I<EXPERIMENTAL> and subject to change.
2085
2086Try to increase the current file descriptor limit(s) to at least C<$numfd>
2087by changing the soft or hard file descriptor resource limit. If C<$numfd>
2088is missing, it will try to set a very high limit, although this is not
2089recommended when you know the actual minimum that you require.
2090
2091If the limit cannot be raised enough, the function makes a best-effort
2092attempt to increase the limit as much as possible, using various
2093tricks, while still failing. You can query the resulting limit using
2094C<IO::AIO::get_fdlimit>.
2095
2096If an error occurs, returns C<undef> and sets C<$!>, otherwise returns
2097true.
2066 2098
2067=item IO::AIO::sendfile $ofh, $ifh, $offset, $count 2099=item IO::AIO::sendfile $ofh, $ifh, $offset, $count
2068 2100
2069Calls the C<eio_sendfile_sync> function, which is like C<aio_sendfile>, 2101Calls the C<eio_sendfile_sync> function, which is like C<aio_sendfile>,
2070but is blocking (this makes most sense if you know the input data is 2102but is blocking (this makes most sense if you know the input data is
2087=item IO::AIO::madvise $scalar, $offset, $len, $advice 2119=item IO::AIO::madvise $scalar, $offset, $len, $advice
2088 2120
2089Simply calls the C<posix_madvise> function (see its 2121Simply calls the C<posix_madvise> function (see its
2090manpage for details). The following advice constants are 2122manpage for details). The following advice constants are
2091available: C<IO::AIO::MADV_NORMAL>, C<IO::AIO::MADV_SEQUENTIAL>, 2123available: C<IO::AIO::MADV_NORMAL>, C<IO::AIO::MADV_SEQUENTIAL>,
2092C<IO::AIO::MADV_RANDOM>, C<IO::AIO::MADV_WILLNEED>, C<IO::AIO::MADV_DONTNEED>, 2124C<IO::AIO::MADV_RANDOM>, C<IO::AIO::MADV_WILLNEED>,
2093C<IO::AIO::MADV_FREE>. 2125C<IO::AIO::MADV_DONTNEED>.
2094 2126
2095If C<$offset> is negative, counts from the end. If C<$length> is negative, 2127If C<$offset> is negative, counts from the end. If C<$length> is negative,
2096the remaining length of the C<$scalar> is used. If possible, C<$length> 2128the remaining length of the C<$scalar> is used. If possible, C<$length>
2097will be reduced to fit into the C<$scalar>. 2129will be reduced to fit into the C<$scalar>.
2098 2130

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines