ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/README
(Generate patch)

Comparing IO-AIO/README (file contents):
Revision 1.59 by root, Tue Feb 20 06:54:47 2018 UTC vs.
Revision 1.62 by root, Sat Aug 25 19:59:18 2018 UTC

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
468 will be emulated by simply reading the data, which would have a 469 will be emulated by simply reading the data, which would have a
469 similar effect. 470 similar effect.
470 471
471 aio_stat $fh_or_path, $callback->($status) 472 aio_stat $fh_or_path, $callback->($status)
472 aio_lstat $fh, $callback->($status) 473 aio_lstat $fh, $callback->($status)
473 Works like perl's "stat" or "lstat" in void context. The callback 474 Works almost exactly like perl's "stat" or "lstat" in void context.
474 will be called after the stat and the results will be available 475 The callback will be called after the stat and the results will be
475 using "stat _" or "-s _" etc... 476 available using "stat _" or "-s _" and other tests (with the
477 exception of "-B" and "-T").
476 478
477 The pathname passed to "aio_stat" must be absolute. See API NOTES, 479 The pathname passed to "aio_stat" must be absolute. See API NOTES,
478 above, for an explanation. 480 above, for an explanation.
479 481
480 Currently, the stats are always 64-bit-stats, i.e. instead of 482 Currently, the stats are always 64-bit-stats, i.e. instead of
488 back on traditional behaviour). 490 back on traditional behaviour).
489 491
490 "S_IFMT", "S_IFIFO", "S_IFCHR", "S_IFBLK", "S_IFLNK", "S_IFREG", 492 "S_IFMT", "S_IFIFO", "S_IFCHR", "S_IFBLK", "S_IFLNK", "S_IFREG",
491 "S_IFDIR", "S_IFWHT", "S_IFSOCK", "IO::AIO::major $dev_t", 493 "S_IFDIR", "S_IFWHT", "S_IFSOCK", "IO::AIO::major $dev_t",
492 "IO::AIO::minor $dev_t", "IO::AIO::makedev $major, $minor". 494 "IO::AIO::minor $dev_t", "IO::AIO::makedev $major, $minor".
495
496 To access higher resolution stat timestamps, see "SUBSECOND STAT
497 TIME ACCESS".
493 498
494 Example: Print the length of /etc/passwd: 499 Example: Print the length of /etc/passwd:
495 500
496 aio_stat "/etc/passwd", sub { 501 aio_stat "/etc/passwd", sub {
497 $_[0] and die "stat failed: $!"; 502 $_[0] and die "stat failed: $!";
544 aio_utime $fh_or_path, $atime, $mtime, $callback->($status) 549 aio_utime $fh_or_path, $atime, $mtime, $callback->($status)
545 Works like perl's "utime" function (including the special case of 550 Works like perl's "utime" function (including the special case of
546 $atime and $mtime being undef). Fractional times are supported if 551 $atime and $mtime being undef). Fractional times are supported if
547 the underlying syscalls support them. 552 the underlying syscalls support them.
548 553
549 When called with a pathname, uses utimes(2) if available, otherwise 554 When called with a pathname, uses utimensat(2) or utimes(2) if
550 utime(2). If called on a file descriptor, uses futimes(2) if 555 available, otherwise utime(2). If called on a file descriptor, uses
551 available, otherwise returns ENOSYS, so this is not portable. 556 futimens(2) or futimes(2) if available, otherwise returns ENOSYS, so
557 this is not portable.
552 558
553 Examples: 559 Examples:
554 560
555 # set atime and mtime to current time (basically touch(1)): 561 # set atime and mtime to current time (basically touch(1)):
556 aio_utime "path", undef, undef; 562 aio_utime "path", undef, undef;
686 The flags are a combination of the following constants, ORed 692 The flags are a combination of the following constants, ORed
687 together (the flags will also be passed to the callback, possibly 693 together (the flags will also be passed to the callback, possibly
688 modified): 694 modified):
689 695
690 IO::AIO::READDIR_DENTS 696 IO::AIO::READDIR_DENTS
691 When this flag is off, then the callback gets an arrayref 697 Normally the callback gets an arrayref consisting of names only
692 consisting of names only (as with "aio_readdir"), otherwise it 698 (as with "aio_readdir"). If this flag is set, then the callback
693 gets an arrayref with "[$name, $type, $inode]" arrayrefs, each 699 gets an arrayref with "[$name, $type, $inode]" arrayrefs, each
694 describing a single directory entry in more detail. 700 describing a single directory entry in more detail:
695 701
696 $name is the name of the entry. 702 $name is the name of the entry.
697 703
698 $type is one of the "IO::AIO::DT_xxx" constants: 704 $type is one of the "IO::AIO::DT_xxx" constants:
699 705
700 "IO::AIO::DT_UNKNOWN", "IO::AIO::DT_FIFO", "IO::AIO::DT_CHR", 706 "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", 707 "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". 708 "IO::AIO::DT_LNK", "IO::AIO::DT_SOCK", "IO::AIO::DT_WHT".
703 709
704 "IO::AIO::DT_UNKNOWN" means just that: readdir does not know. If 710 "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 711 you need to know, you have to run stat yourself. Also, for
706 reasons, the $type scalars are read-only: you can not modify 712 speed/memory reasons, the $type scalars are read-only: you must
707 them. 713 not modify them.
708 714
709 $inode is the inode number (which might not be exact on systems 715 $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 716 with 64 bit inode numbers and 32 bit perls). This field has
711 unspecified content on systems that do not deliver the inode 717 unspecified content on systems that do not deliver the inode
712 information. 718 information.
724 of which names with short names are tried first. 730 of which names with short names are tried first.
725 731
726 IO::AIO::READDIR_STAT_ORDER 732 IO::AIO::READDIR_STAT_ORDER
727 When this flag is set, then the names will be returned in an 733 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 734 order suitable for stat()'ing each one. That is, when you plan
729 to stat() all files in the given directory, then the returned 735 to stat() most or all files in the given directory, then the
730 order will likely be fastest. 736 returned order will likely be faster.
731 737
732 If both this flag and "IO::AIO::READDIR_DIRS_FIRST" are 738 If both this flag and "IO::AIO::READDIR_DIRS_FIRST" are
733 specified, then the likely dirs come first, resulting in a less 739 specified, then the likely dirs come first, resulting in a less
734 optimal stat order. 740 optimal stat order for stat'ing all entries, but likely a more
741 optimal order for finding subdirectories.
735 742
736 IO::AIO::READDIR_FOUND_UNKNOWN 743 IO::AIO::READDIR_FOUND_UNKNOWN
737 This flag should not be set when calling "aio_readdirx". 744 This flag should not be set when calling "aio_readdirx".
738 Instead, it is being set by "aio_readdirx", when any of the 745 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 746 $type's found were "IO::AIO::DT_UNKNOWN". The absence of this
1446 Strictly equivalent to: 1453 Strictly equivalent to:
1447 1454
1448 IO::AIO::poll_wait, IO::AIO::poll_cb 1455 IO::AIO::poll_wait, IO::AIO::poll_cb
1449 while IO::AIO::nreqs; 1456 while IO::AIO::nreqs;
1450 1457
1458 This function can be useful at program aborts, to make sure
1459 outstanding I/O has been done ("IO::AIO" uses an "END" block which
1460 already calls this function on normal exits), or when you are merely
1461 using "IO::AIO" for its more advanced functions, rather than for
1462 async I/O, e.g.:
1463
1464 my ($dirs, $nondirs);
1465 IO::AIO::aio_scandir "/tmp", 0, sub { ($dirs, $nondirs) = @_ };
1466 IO::AIO::flush;
1467 # $dirs, $nondirs are now set
1468
1451 IO::AIO::max_poll_reqs $nreqs 1469 IO::AIO::max_poll_reqs $nreqs
1452 IO::AIO::max_poll_time $seconds 1470 IO::AIO::max_poll_time $seconds
1453 These set the maximum number of requests (default 0, meaning 1471 These set the maximum number of requests (default 0, meaning
1454 infinity) that are being processed by "IO::AIO::poll_cb" in one 1472 infinity) that are being processed by "IO::AIO::poll_cb" in one
1455 call, respectively the maximum amount of time (default 0, meaning 1473 call, respectively the maximum amount of time (default 0, meaning
1587 executed). 1605 executed).
1588 1606
1589 IO::AIO::npending 1607 IO::AIO::npending
1590 Returns the number of requests currently in the pending state 1608 Returns the number of requests currently in the pending state
1591 (executed, but not yet processed by poll_cb). 1609 (executed, but not yet processed by poll_cb).
1610
1611 SUBSECOND STAT TIME ACCESS
1612 Both "aio_stat"/"aio_lstat" and perl's "stat"/"lstat" functions can
1613 generally find access/modification and change times with subsecond time
1614 accuracy of the system supports it, but perl's built-in functions only
1615 return the integer part.
1616
1617 The following functions return the timestamps of the most recent stat
1618 with subsecond precision on most systems and work both after
1619 "aio_stat"/"aio_lstat" and perl's "stat"/"lstat" calls. Their return
1620 value is only meaningful after a successful "stat"/"lstat" call, or
1621 during/after a successful "aio_stat"/"aio_lstat" callback.
1622
1623 This is similar to the Time::HiRes "stat" functions, but can return full
1624 resolution without rounding and work with standard perl "stat",
1625 alleviating the need to call the special "Time::HiRes" functions, which
1626 do not act like their perl counterparts.
1627
1628 On operating systems or file systems where subsecond time resolution is
1629 not supported or could not be detected, a fractional part of 0 is
1630 returned, so it is always safe to call these functions.
1631
1632 $seconds = IO::AIO::st_atime, IO::AIO::st_mtime, IO::AIO::st_ctime,
1633 IO::AIO::st_btime
1634 Return the access, modication, change or birth time, respectively,
1635 including fractional part. Due to the limited precision of floating
1636 point, the accuracy on most platforms is only a bit better than
1637 milliseconds for times around now - see the *nsec* function family,
1638 below, for full accuracy.
1639
1640 File birth time is only available when the OS and perl support it
1641 (on FreeBSD and NetBSD at the time of this writing, although support
1642 is adaptive, so if your OS/perl gains support, IO::AIO can take
1643 avdantage of it). On systems where it isn't available, 0 is
1644 currently returned, but this might change to "undef" in a future
1645 version.
1646
1647 ($atime, $mtime, $ctime, $btime, ...) = IO::AIO::st_xtime
1648 Returns access, modification, change and birth time all in one go,
1649 and maybe more times in the future version.
1650
1651 $nanoseconds = IO::AIO::st_atimensec, IO::AIO::st_mtimensec,
1652 IO::AIO::st_ctimensec, IO::AIO::st_btimensec
1653 Return the fractional access, modifcation, change or birth time, in
1654 nanoseconds, as an integer in the range 0 to 999999999.
1655
1656 Note that no accessors are provided for access, modification and
1657 change times - you need to get those from "stat _" if required ("int
1658 IO::AIO::st_atime" and so on will *not* generally give you the
1659 correct value).
1660
1661 $seconds = IO::AIO::st_btimesec
1662 The (integral) seconds part of the file birth time, if available.
1663
1664 ($atime, $mtime, $ctime, $btime, ...) = IO::AIO::st_xtimensec
1665 Like the functions above, but returns all four times in one go (and
1666 maybe more in future versions).
1667
1668 $counter = IO::AIO::st_gen
1669 Returns the generation counter of the file. This is only available
1670 on platforms which have this member in their "struct stat" (most
1671 BSDs at the time of this writing) and generally only to the root
1672 usert. If unsupported, 0 is returned, but this might change to
1673 "undef" in a future version.
1674
1675 Example: print the high resolution modification time of /etc, using
1676 "stat", and "IO::AIO::aio_stat".
1677
1678 if (stat "/etc") {
1679 printf "stat(/etc) mtime: %f\n", IO::AIO::st_mtime;
1680 }
1681
1682 IO::AIO::aio_stat "/etc", sub {
1683 $_[0]
1684 and return;
1685
1686 printf "aio_stat(/etc) mtime: %d.%09d\n", (stat _)[9], IO::AIO::st_mtimensec;
1687 };
1688
1689 IO::AIO::flush;
1690
1691 Output of the awbove on my system, showing reduced and full accuracy:
1692
1693 stat(/etc) mtime: 1534043702.020808
1694 aio_stat(/etc) mtime: 1534043702.020807792
1592 1695
1593 MISCELLANEOUS FUNCTIONS 1696 MISCELLANEOUS FUNCTIONS
1594 IO::AIO implements some functions that are useful when you want to use 1697 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 1698 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_*" 1699 "Asynchronous I/O" route. Many of these have an asynchronous "aio_*"
1724 my $fast_md5 = md5 $data; 1827 my $fast_md5 = md5 $data;
1725 1828
1726 IO::AIO::munmap $scalar 1829 IO::AIO::munmap $scalar
1727 Removes a previous mmap and undefines the $scalar. 1830 Removes a previous mmap and undefines the $scalar.
1728 1831
1832 IO::AIO::mremap $scalar, $new_length, $flags = MREMAP_MAYMOVE[,
1833 $new_address = 0]
1834 Calls the Linux-specific mremap(2) system call. The $scalar must
1835 have been mapped by "IO::AIO::mmap", and $flags must currently
1836 either be 0 or "IO::AIO::MREMAP_MAYMOVE".
1837
1838 Returns true if successful, and false otherwise. If the underlying
1839 mmapped region has changed address, then the true value has the
1840 numerical value 1, otherwise it has the numerical value 0:
1841
1842 my $success = IO::AIO::mremap $mmapped, 8192, IO::AIO::MREMAP_MAYMOVE
1843 or die "mremap: $!";
1844
1845 if ($success*1) {
1846 warn "scalar has chanegd address in memory\n";
1847 }
1848
1849 "IO::AIO::MREMAP_FIXED" and the $new_address argument are currently
1850 implemented, but not supported and might go away in a future
1851 version.
1852
1853 On systems where this call is not supported or is not emulated, this
1854 call returns falls and sets $! to "ENOSYS".
1855
1729 IO::AIO::munlock $scalar, $offset = 0, $length = undef 1856 IO::AIO::munlock $scalar, $offset = 0, $length = undef
1730 Calls the "munlock" function, undoing the effects of a previous 1857 Calls the "munlock" function, undoing the effects of a previous
1731 "aio_mlock" call (see its description for details). 1858 "aio_mlock" call (see its description for details).
1732 1859
1733 IO::AIO::munlockall 1860 IO::AIO::munlockall

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines