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.286 by root, Sun Jul 22 20:39:19 2018 UTC vs.
Revision 1.292 by root, Tue Aug 14 09:29:50 2018 UTC

171use common::sense; 171use common::sense;
172 172
173use base 'Exporter'; 173use base 'Exporter';
174 174
175BEGIN { 175BEGIN {
176 our $VERSION = 4.42; 176 our $VERSION = 4.53;
177 177
178 our @AIO_REQ = qw(aio_sendfile aio_seek aio_read aio_write aio_open aio_close 178 our @AIO_REQ = qw(aio_sendfile aio_seek aio_read aio_write aio_open aio_close
179 aio_stat aio_lstat aio_unlink aio_rmdir aio_readdir aio_readdirx 179 aio_stat aio_lstat aio_unlink aio_rmdir aio_readdir aio_readdirx
180 aio_scandir aio_symlink aio_readlink aio_realpath aio_fcntl aio_ioctl 180 aio_scandir aio_symlink aio_readlink aio_realpath aio_fcntl aio_ioctl
181 aio_sync aio_fsync aio_syncfs aio_fdatasync aio_sync_file_range 181 aio_sync aio_fsync aio_syncfs aio_fdatasync aio_sync_file_range
561 561
562C<S_IFMT>, C<S_IFIFO>, C<S_IFCHR>, C<S_IFBLK>, C<S_IFLNK>, C<S_IFREG>, 562C<S_IFMT>, C<S_IFIFO>, C<S_IFCHR>, C<S_IFBLK>, C<S_IFLNK>, C<S_IFREG>,
563C<S_IFDIR>, C<S_IFWHT>, C<S_IFSOCK>, C<IO::AIO::major $dev_t>, 563C<S_IFDIR>, C<S_IFWHT>, C<S_IFSOCK>, C<IO::AIO::major $dev_t>,
564C<IO::AIO::minor $dev_t>, C<IO::AIO::makedev $major, $minor>. 564C<IO::AIO::minor $dev_t>, C<IO::AIO::makedev $major, $minor>.
565 565
566To access higher resolution stat timestamps, see L<SUBSECOND STAT TIME
567ACCESS>.
568
566Example: Print the length of F</etc/passwd>: 569Example: Print the length of F</etc/passwd>:
567 570
568 aio_stat "/etc/passwd", sub { 571 aio_stat "/etc/passwd", sub {
569 $_[0] and die "stat failed: $!"; 572 $_[0] and die "stat failed: $!";
570 print "size is ", -s _, "\n"; 573 print "size is ", -s _, "\n";
2010Returns the number of requests currently in the pending state (executed, 2013Returns the number of requests currently in the pending state (executed,
2011but not yet processed by poll_cb). 2014but not yet processed by poll_cb).
2012 2015
2013=back 2016=back
2014 2017
2018=head3 SUBSECOND STAT TIME ACCESS
2019
2020Both C<aio_stat>/C<aio_lstat> and perl's C<stat>/C<lstat> functions can
2021generally find access/modification and change times with subsecond time
2022accuracy of the system supports it, but perl's built-in functions only
2023return the integer part.
2024
2025The following functions return the timestamps of the most recent
2026stat with subsecond precision on most systems and work both after
2027C<aio_stat>/C<aio_lstat> and perl's C<stat>/C<lstat> calls. Their return
2028value is only meaningful after a successful C<stat>/C<lstat> call, or
2029during/after a successful C<aio_stat>/C<aio_lstat> callback.
2030
2031This is similar to the L<Time::HiRes> C<stat> functions, but can return
2032full resolution without rounding and work with standard perl C<stat>,
2033alleviating the need to call the special C<Time::HiRes> functions, which
2034do not act like their perl counterparts.
2035
2036On operating systems or file systems where subsecond time resolution is
2037not supported or could not be detected, a fractional part of C<0> is
2038returned, so it is always safe to call these functions.
2039
2040=over 4
2041
2042=item $seconds = IO::AIO::st_atime, IO::AIO::st_mtime, IO::AIO::st_ctime
2043
2044Return the access, modication or change time, respectively, including
2045fractional part. Due to the limited precision of floating point, the
2046accuracy on most platforms is only a bit better than milliseconds for
2047times around now - see the I<nsec> function family, below, for full
2048accuracy.
2049
2050=item ($atime, $mtime, $ctime, ...) = IO::AIO::st_xtime
2051
2052Returns access, modification and change time all in one go, and maybe more
2053times in the future version.
2054
2055=item $nanoseconds = IO::AIO::st_atimensec, IO::AIO::st_mtimensec, IO::AIO::st_ctimensec
2056
2057Return the fractional access, modifcation or change time, in nanoseconds,
2058as an integer in the range C<0> to C<999999999>.
2059
2060=item ($atime, $mtime, $ctime, ...) = IO::AIO::st_xtimensec
2061
2062Like the functions above, but returns all three times in one go (and maybe
2063more in future versions).
2064
2065=back
2066
2067Example: print the high resolution modification time of F</etc>, using
2068C<stat>, and C<IO::AIO::aio_stat>.
2069
2070 if (stat "/etc") {
2071 printf "stat(/etc) mtime: %f\n", IO::AIO::st_mtime;
2072 }
2073
2074 IO::AIO::aio_stat "/etc", sub {
2075 $_[0]
2076 and return;
2077
2078 printf "aio_stat(/etc) mtime: %d.%09d\n", (stat _)[9], IO::AIO::st_mtimensec;
2079 };
2080
2081 IO::AIO::flush;
2082
2083Output of the awbove on my system, showing reduced and full accuracy:
2084
2085 stat(/etc) mtime: 1534043702.020808
2086 aio_stat(/etc) mtime: 1534043702.020807792
2087
2015=head3 MISCELLANEOUS FUNCTIONS 2088=head3 MISCELLANEOUS FUNCTIONS
2016 2089
2017IO::AIO implements some functions that are useful when you want to use 2090IO::AIO implements some functions that are useful when you want to use
2018some "Advanced I/O" function not available to in Perl, without going the 2091some "Advanced I/O" function not available to in Perl, without going the
2019"Asynchronous I/O" route. Many of these have an asynchronous C<aio_*> 2092"Asynchronous I/O" route. Many of these have an asynchronous C<aio_*>
2159 2232
2160=item IO::AIO::munmap $scalar 2233=item IO::AIO::munmap $scalar
2161 2234
2162Removes a previous mmap and undefines the C<$scalar>. 2235Removes a previous mmap and undefines the C<$scalar>.
2163 2236
2164=item IO::AIO::mremap $scalar, $new_length, $flags = 0[, $new_address = 0] 2237=item IO::AIO::mremap $scalar, $new_length, $flags = MREMAP_MAYMOVE[, $new_address = 0]
2165 2238
2166Calls the Linux-specific mremap(2) system call. The C<$scalar> must have 2239Calls the Linux-specific mremap(2) system call. The C<$scalar> must have
2167been mapped by C<IO::AIO::mmap>, and C<$flags> must currently either be 2240been mapped by C<IO::AIO::mmap>, and C<$flags> must currently either be
2168C<0> or C<IO::AIO::MREMAP_MAYMOVE>. 2241C<0> or C<IO::AIO::MREMAP_MAYMOVE>.
2169 2242

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines