… | |
… | |
228 | |
228 | |
229 | IO::AIO::sendfile $ofh, $ifh, $offset, $count |
229 | IO::AIO::sendfile $ofh, $ifh, $offset, $count |
230 | IO::AIO::fadvise $fh, $offset, $len, $advice |
230 | IO::AIO::fadvise $fh, $offset, $len, $advice |
231 | IO::AIO::mmap $scalar, $length, $prot, $flags[, $fh[, $offset]] |
231 | IO::AIO::mmap $scalar, $length, $prot, $flags[, $fh[, $offset]] |
232 | IO::AIO::munmap $scalar |
232 | IO::AIO::munmap $scalar |
|
|
233 | IO::AIO::mremap $scalar, $new_length, $flags[, $new_address] |
233 | IO::AIO::madvise $scalar, $offset, $length, $advice |
234 | IO::AIO::madvise $scalar, $offset, $length, $advice |
234 | IO::AIO::mprotect $scalar, $offset, $length, $protect |
235 | IO::AIO::mprotect $scalar, $offset, $length, $protect |
235 | IO::AIO::munlock $scalar, $offset = 0, $length = undef |
236 | IO::AIO::munlock $scalar, $offset = 0, $length = undef |
236 | IO::AIO::munlockall |
237 | IO::AIO::munlockall |
237 | |
238 | |
… | |
… | |
339 | "O_APPEND"), the following POSIX and non-POSIX constants are |
340 | "O_APPEND"), the following POSIX and non-POSIX constants are |
340 | available (missing ones on your system are, as usual, 0): |
341 | available (missing ones on your system are, as usual, 0): |
341 | |
342 | |
342 | "O_ASYNC", "O_DIRECT", "O_NOATIME", "O_CLOEXEC", "O_NOCTTY", |
343 | "O_ASYNC", "O_DIRECT", "O_NOATIME", "O_CLOEXEC", "O_NOCTTY", |
343 | "O_NOFOLLOW", "O_NONBLOCK", "O_EXEC", "O_SEARCH", "O_DIRECTORY", |
344 | "O_NOFOLLOW", "O_NONBLOCK", "O_EXEC", "O_SEARCH", "O_DIRECTORY", |
344 | "O_DSYNC", "O_RSYNC", "O_SYNC", "O_PATH", "O_TMPFILE", and |
345 | "O_DSYNC", "O_RSYNC", "O_SYNC", "O_PATH", "O_TMPFILE", "O_TTY_INIT" |
345 | "O_TTY_INIT". |
346 | and "O_ACCMODE". |
346 | |
347 | |
347 | aio_close $fh, $callback->($status) |
348 | aio_close $fh, $callback->($status) |
348 | Asynchronously close a file and call the callback with the result |
349 | Asynchronously close a file and call the callback with the result |
349 | code. |
350 | code. |
350 | |
351 | |
… | |
… | |
488 | back on traditional behaviour). |
489 | back on traditional behaviour). |
489 | |
490 | |
490 | "S_IFMT", "S_IFIFO", "S_IFCHR", "S_IFBLK", "S_IFLNK", "S_IFREG", |
491 | "S_IFMT", "S_IFIFO", "S_IFCHR", "S_IFBLK", "S_IFLNK", "S_IFREG", |
491 | "S_IFDIR", "S_IFWHT", "S_IFSOCK", "IO::AIO::major $dev_t", |
492 | "S_IFDIR", "S_IFWHT", "S_IFSOCK", "IO::AIO::major $dev_t", |
492 | "IO::AIO::minor $dev_t", "IO::AIO::makedev $major, $minor". |
493 | "IO::AIO::minor $dev_t", "IO::AIO::makedev $major, $minor". |
|
|
494 | |
|
|
495 | To access higher resolution stat timestamps, see "SUBSECOND STAT |
|
|
496 | TIME ACCESS". |
493 | |
497 | |
494 | Example: Print the length of /etc/passwd: |
498 | Example: Print the length of /etc/passwd: |
495 | |
499 | |
496 | aio_stat "/etc/passwd", sub { |
500 | aio_stat "/etc/passwd", sub { |
497 | $_[0] and die "stat failed: $!"; |
501 | $_[0] and die "stat failed: $!"; |
… | |
… | |
686 | The flags are a combination of the following constants, ORed |
690 | The flags are a combination of the following constants, ORed |
687 | together (the flags will also be passed to the callback, possibly |
691 | together (the flags will also be passed to the callback, possibly |
688 | modified): |
692 | modified): |
689 | |
693 | |
690 | IO::AIO::READDIR_DENTS |
694 | IO::AIO::READDIR_DENTS |
691 | When this flag is off, then the callback gets an arrayref |
695 | Normally the callback gets an arrayref consisting of names only |
692 | consisting of names only (as with "aio_readdir"), otherwise it |
696 | (as with "aio_readdir"). If this flag is set, then the callback |
693 | gets an arrayref with "[$name, $type, $inode]" arrayrefs, each |
697 | gets an arrayref with "[$name, $type, $inode]" arrayrefs, each |
694 | describing a single directory entry in more detail. |
698 | describing a single directory entry in more detail: |
695 | |
699 | |
696 | $name is the name of the entry. |
700 | $name is the name of the entry. |
697 | |
701 | |
698 | $type is one of the "IO::AIO::DT_xxx" constants: |
702 | $type is one of the "IO::AIO::DT_xxx" constants: |
699 | |
703 | |
700 | "IO::AIO::DT_UNKNOWN", "IO::AIO::DT_FIFO", "IO::AIO::DT_CHR", |
704 | "IO::AIO::DT_UNKNOWN", "IO::AIO::DT_FIFO", "IO::AIO::DT_CHR", |
701 | "IO::AIO::DT_DIR", "IO::AIO::DT_BLK", "IO::AIO::DT_REG", |
705 | "IO::AIO::DT_DIR", "IO::AIO::DT_BLK", "IO::AIO::DT_REG", |
702 | "IO::AIO::DT_LNK", "IO::AIO::DT_SOCK", "IO::AIO::DT_WHT". |
706 | "IO::AIO::DT_LNK", "IO::AIO::DT_SOCK", "IO::AIO::DT_WHT". |
703 | |
707 | |
704 | "IO::AIO::DT_UNKNOWN" means just that: readdir does not know. If |
708 | "IO::AIO::DT_UNKNOWN" means just that: readdir does not know. If |
705 | you need to know, you have to run stat yourself. Also, for speed |
709 | you need to know, you have to run stat yourself. Also, for |
706 | reasons, the $type scalars are read-only: you can not modify |
710 | speed/memory reasons, the $type scalars are read-only: you must |
707 | them. |
711 | not modify them. |
708 | |
712 | |
709 | $inode is the inode number (which might not be exact on systems |
713 | $inode is the inode number (which might not be exact on systems |
710 | with 64 bit inode numbers and 32 bit perls). This field has |
714 | with 64 bit inode numbers and 32 bit perls). This field has |
711 | unspecified content on systems that do not deliver the inode |
715 | unspecified content on systems that do not deliver the inode |
712 | information. |
716 | information. |
… | |
… | |
724 | of which names with short names are tried first. |
728 | of which names with short names are tried first. |
725 | |
729 | |
726 | IO::AIO::READDIR_STAT_ORDER |
730 | IO::AIO::READDIR_STAT_ORDER |
727 | When this flag is set, then the names will be returned in an |
731 | When this flag is set, then the names will be returned in an |
728 | order suitable for stat()'ing each one. That is, when you plan |
732 | order suitable for stat()'ing each one. That is, when you plan |
729 | to stat() all files in the given directory, then the returned |
733 | to stat() most or all files in the given directory, then the |
730 | order will likely be fastest. |
734 | returned order will likely be faster. |
731 | |
735 | |
732 | If both this flag and "IO::AIO::READDIR_DIRS_FIRST" are |
736 | If both this flag and "IO::AIO::READDIR_DIRS_FIRST" are |
733 | specified, then the likely dirs come first, resulting in a less |
737 | specified, then the likely dirs come first, resulting in a less |
734 | optimal stat order. |
738 | optimal stat order for stat'ing all entries, but likely a more |
|
|
739 | optimal order for finding subdirectories. |
735 | |
740 | |
736 | IO::AIO::READDIR_FOUND_UNKNOWN |
741 | IO::AIO::READDIR_FOUND_UNKNOWN |
737 | This flag should not be set when calling "aio_readdirx". |
742 | This flag should not be set when calling "aio_readdirx". |
738 | Instead, it is being set by "aio_readdirx", when any of the |
743 | Instead, it is being set by "aio_readdirx", when any of the |
739 | $type's found were "IO::AIO::DT_UNKNOWN". The absence of this |
744 | $type's found were "IO::AIO::DT_UNKNOWN". The absence of this |
… | |
… | |
1588 | |
1593 | |
1589 | IO::AIO::npending |
1594 | IO::AIO::npending |
1590 | Returns the number of requests currently in the pending state |
1595 | Returns the number of requests currently in the pending state |
1591 | (executed, but not yet processed by poll_cb). |
1596 | (executed, but not yet processed by poll_cb). |
1592 | |
1597 | |
|
|
1598 | SUBSECOND STAT TIME ACCESS |
|
|
1599 | Both "aio_stat"/"aio_lstat" and perl's "stat"/"lstat" functions can |
|
|
1600 | generally find access/modification and change times with subsecond time |
|
|
1601 | accuracy of the system supports it, but perl's built-in functions only |
|
|
1602 | return the integer part. |
|
|
1603 | |
|
|
1604 | The following functions return the timestamps of the most recent stat |
|
|
1605 | with subsecond precision on most systems and work both after |
|
|
1606 | "aio_stat"/"aio_lstat" and perl's "stat"/"lstat" calls. Their return |
|
|
1607 | value is only meaningful after a successful "stat"/"lstat" call, or |
|
|
1608 | during/after a successful "aio_stat"/"aio_lstat" callback. |
|
|
1609 | |
|
|
1610 | This is similar to the Time::HiRes "stat" functions, but can return full |
|
|
1611 | resolution without rounding and work with standard perl "stat", |
|
|
1612 | alleviating the need to call the special "Time::HiRes" functions, which |
|
|
1613 | do not act like their perl counterparts. |
|
|
1614 | |
|
|
1615 | On operating systems or file systems where subsecond time resolution is |
|
|
1616 | not supported or could not be detected, a fractional part of 0 is |
|
|
1617 | returned, so it is always safe to call these functions. |
|
|
1618 | |
|
|
1619 | $seconds = IO::AIO::st_atime, IO::AIO::st_mtime, IO::AIO::st_ctime |
|
|
1620 | Return the access, modication or change time, respectively, |
|
|
1621 | including fractional part. Due to the limited precision of floating |
|
|
1622 | point, the accuracy on most platforms is only a bit better than |
|
|
1623 | milliseconds for times around now - see the *nsec* function family, |
|
|
1624 | below, for full accuracy. |
|
|
1625 | |
|
|
1626 | ($atime, $mtime, $ctime, ...) = IO::AIO::st_xtime |
|
|
1627 | Returns access, modification and change time all in one go, and |
|
|
1628 | maybe more times in the future version. |
|
|
1629 | |
|
|
1630 | $nanoseconds = IO::AIO::st_atimensec, IO::AIO::st_mtimensec, |
|
|
1631 | IO::AIO::st_ctimensec |
|
|
1632 | Return the fractional access, modifcation or change time, in |
|
|
1633 | nanoseconds, as an integer in the range 0 to 999999999. |
|
|
1634 | |
|
|
1635 | ($atime, $mtime, $ctime, ...) = IO::AIO::st_xtimensec |
|
|
1636 | Like the functions above, but returns all three times in one go (and |
|
|
1637 | maybe more in future versions). |
|
|
1638 | |
|
|
1639 | Example: print the high resolution modification time of /etc, using |
|
|
1640 | "stat", and "IO::AIO::aio_stat". |
|
|
1641 | |
|
|
1642 | if (stat "/etc") { |
|
|
1643 | printf "stat(/etc) mtime: %f\n", IO::AIO::st_mtime; |
|
|
1644 | } |
|
|
1645 | |
|
|
1646 | IO::AIO::aio_stat "/etc", sub { |
|
|
1647 | $_[0] |
|
|
1648 | and return; |
|
|
1649 | |
|
|
1650 | printf "aio_stat(/etc) mtime: %d.%09d\n", (stat _)[9], IO::AIO::st_mtimensec; |
|
|
1651 | }; |
|
|
1652 | |
|
|
1653 | IO::AIO::flush; |
|
|
1654 | |
|
|
1655 | Output of the awbove on my system, showing reduced and full accuracy: |
|
|
1656 | |
|
|
1657 | stat(/etc) mtime: 1534043702.020808 |
|
|
1658 | aio_stat(/etc) mtime: 1534043702.020807792 |
|
|
1659 | |
1593 | MISCELLANEOUS FUNCTIONS |
1660 | MISCELLANEOUS FUNCTIONS |
1594 | IO::AIO implements some functions that are useful when you want to use |
1661 | IO::AIO implements some functions that are useful when you want to use |
1595 | some "Advanced I/O" function not available to in Perl, without going the |
1662 | some "Advanced I/O" function not available to in Perl, without going the |
1596 | "Asynchronous I/O" route. Many of these have an asynchronous "aio_*" |
1663 | "Asynchronous I/O" route. Many of these have an asynchronous "aio_*" |
1597 | counterpart. |
1664 | counterpart. |
… | |
… | |
1724 | my $fast_md5 = md5 $data; |
1791 | my $fast_md5 = md5 $data; |
1725 | |
1792 | |
1726 | IO::AIO::munmap $scalar |
1793 | IO::AIO::munmap $scalar |
1727 | Removes a previous mmap and undefines the $scalar. |
1794 | Removes a previous mmap and undefines the $scalar. |
1728 | |
1795 | |
|
|
1796 | IO::AIO::mremap $scalar, $new_length, $flags = MREMAP_MAYMOVE[, |
|
|
1797 | $new_address = 0] |
|
|
1798 | Calls the Linux-specific mremap(2) system call. The $scalar must |
|
|
1799 | have been mapped by "IO::AIO::mmap", and $flags must currently |
|
|
1800 | either be 0 or "IO::AIO::MREMAP_MAYMOVE". |
|
|
1801 | |
|
|
1802 | Returns true if successful, and false otherwise. If the underlying |
|
|
1803 | mmapped region has changed address, then the true value has the |
|
|
1804 | numerical value 1, otherwise it has the numerical value 0: |
|
|
1805 | |
|
|
1806 | my $success = IO::AIO::mremap $mmapped, 8192, IO::AIO::MREMAP_MAYMOVE |
|
|
1807 | or die "mremap: $!"; |
|
|
1808 | |
|
|
1809 | if ($success*1) { |
|
|
1810 | warn "scalar has chanegd address in memory\n"; |
|
|
1811 | } |
|
|
1812 | |
|
|
1813 | "IO::AIO::MREMAP_FIXED" and the $new_address argument are currently |
|
|
1814 | implemented, but not supported and might go away in a future |
|
|
1815 | version. |
|
|
1816 | |
|
|
1817 | On systems where this call is not supported or is not emulated, this |
|
|
1818 | call returns falls and sets $! to "ENOSYS". |
|
|
1819 | |
1729 | IO::AIO::munlock $scalar, $offset = 0, $length = undef |
1820 | IO::AIO::munlock $scalar, $offset = 0, $length = undef |
1730 | Calls the "munlock" function, undoing the effects of a previous |
1821 | Calls the "munlock" function, undoing the effects of a previous |
1731 | "aio_mlock" call (see its description for details). |
1822 | "aio_mlock" call (see its description for details). |
1732 | |
1823 | |
1733 | IO::AIO::munlockall |
1824 | IO::AIO::munlockall |