--- IO-AIO/AIO.pm 2020/12/29 15:16:27 1.308 +++ IO-AIO/AIO.pm 2023/09/27 03:09:57 1.319 @@ -173,7 +173,7 @@ use base 'Exporter'; BEGIN { - our $VERSION = 4.73; + our $VERSION = 4.80; our @AIO_REQ = qw(aio_sendfile aio_seek aio_read aio_write aio_open aio_close aio_stat aio_lstat aio_unlink aio_rmdir aio_readdir aio_readdirx @@ -194,7 +194,12 @@ nreqs nready npending nthreads max_poll_time max_poll_reqs sendfile fadvise madvise - mmap munmap mremap munlock munlockall); + mmap munmap mremap munlock munlockall + + accept4 tee splice pipe2 pipesize + fexecve mount umount memfd_create eventfd + timerfd_create timerfd_settime timerfd_gettime + pidfd_open pidfd_send_signal pidfd_getfd); push @AIO_REQ, qw(aio_busy); # not exported @@ -287,6 +292,7 @@ IO::AIO::sendfile $ofh, $ifh, $offset, $count IO::AIO::fadvise $fh, $offset, $len, $advice + IO::AIO::fexecve $fh, $argv, $envp IO::AIO::mmap $scalar, $length, $prot, $flags[, $fh[, $offset]] IO::AIO::munmap $scalar @@ -308,14 +314,24 @@ IO::AIO::accept4 $r_fh, $sockaddr, $sockaddr_len, $flags IO::AIO::splice $r_fh, $r_off, $w_fh, $w_off, $length, $flags IO::AIO::tee $r_fh, $w_fh, $length, $flags + $actual_size = IO::AIO::pipesize $r_fh[, $new_size] ($rfh, $wfh) = IO::AIO::pipe2 [$flags] - $fh = IO::AIO::memfd_create $pathname[, $flags] + $fh = IO::AIO::eventfd [$initval, [$flags]] + $fh = IO::AIO::memfd_create $pathname[, $flags] + $fh = IO::AIO::timerfd_create $clockid[, $flags] ($cur_interval, $cur_value) = IO::AIO::timerfd_settime $fh, $flags, $new_interval, $nbw_value ($cur_interval, $cur_value) = IO::AIO::timerfd_gettime $fh + $fh = IO::AIO::pidfd_open $pid[, $flags] + $status = IO::AIO::pidfd_send_signal $pidfh, $signal[, $siginfo[, $flags]] + $fh = IO::AIO::pidfd_getfd $pidfh, $targetfd[, $flags] + + $retval = IO::AIO::mount $special, $path, $fstype, $flags = 0, $data = undef + $retval = IO::AIO::umount $path, $flags = 0 + =head2 API NOTES All the C calls are more or less thin wrappers around the syscall @@ -399,9 +415,6 @@ Asynchronously open or create a file and call the callback with a newly created filehandle for the file (or C in case of an error). -The pathname passed to C must be absolute. See API NOTES, above, -for an explanation. - The C<$flags> argument is a bitmask. See the C module for a list. They are the same as used by C. @@ -571,9 +584,6 @@ using C or C<-s _> and other tests (with the exception of C<-B> and C<-T>). -The pathname passed to C must be absolute. See API NOTES, above, -for an explanation. - Currently, the stats are always 64-bit-stats, i.e. instead of returning an error when stat'ing a large file, the results will be silently truncated unless perl itself is compiled with large file support. @@ -967,6 +977,11 @@ aioreq_pri $pri; add $grp aio_open $dst, O_CREAT | O_WRONLY | O_TRUNC, 0200, sub { if (my $dst_fh = $_[0]) { + + # best-effort preallocate + aioreq_pri $pri; + add $grp aio_allocate $dst_fh, IO::AIO::FALLOC_FL_KEEP_SIZE, 0, $stat[7], sub { }; + aioreq_pri $pri; add $grp aio_sendfile $dst_fh, $src_fh, 0, $stat[7], sub { if ($_[0] == $stat[7]) { @@ -1340,6 +1355,11 @@ C, C, C, C, C, C, C, C, +C, C, C, C, C, C, +C, C, C, C, C, C, +C, C, C, + + =item aio_sync $callback->($status) Asynchronously call sync and call the callback when finished. @@ -2063,12 +2083,13 @@ In other words, this setting does not enforce a queue limit, but can be used to make poll functions block if the limit is exceeded. -This is a very bad function to use in interactive programs because it -blocks, and a bad way to reduce concurrency because it is inexact: Better -use an C together with a feed callback. +This is a bad function to use in interactive programs because it blocks, +and a bad way to reduce concurrency because it is inexact. If you need to +issue many requests without being able to call a poll function on demand, +it is better to use an C together with a feed callback. -Its main use is in scripts without an event loop - when you want to stat -a lot of files, you can write something like this: +Its main use is in scripts without an event loop - when you want to stat a +lot of files, you can write something like this: IO::AIO::max_outstanding 32; @@ -2079,10 +2100,11 @@ IO::AIO::flush; -The call to C inside the loop will normally return instantly, but -as soon as more thna C<32> reqeusts are in-flight, it will block until -some requests have been handled. This keeps the loop from pushing a large -number of C requests onto the queue. +The call to C inside the loop will normally return instantly, +allowing the loop to progress, but as soon as more than C<32> requests +are in-flight, it will block until some requests have been handled. This +keeps the loop from pushing a large number of C requests onto +the queue (which, with many paths to stat, can use up a lot of memory). The default value for C is very large, so there is no practical limit on the number of outstanding requests. @@ -2220,6 +2242,38 @@ =over 4 +=item $retval = IO::AIO::fexecve $fh, $argv, $envp + +A more-or-less direct equivalent to the POSIX C functions, which +allows you to specify the program to be executed via a file descriptor (or +handle). Returns C<-1> and sets errno to C if not available. + +=item $retval = IO::AIO::mount $special, $path, $fstype, $flags = 0, $data = undef + +Calls the GNU/Linux mount syscall with the given arguments. All except +C<$flags> are strings, and if C<$data> is C, a C will be +passed. + +The following values for C<$flags> are available: + +C, C, C, C, C, +C, C, C, C, +C, C, C, C, C, +C, C, C, C, C, +C, C, C, C, +C, C, C, C, C and +C. + +=item $retval = IO::AIO::umount $path, $flags = 0 + +Invokes the GNU/Linux C or C syscalls. Always calls +C if C<$flags> is C<0>, otherwqise always tries to call +C. + +The following C<$flags> are available: + +C, C, C and C. + =item $numfd = IO::AIO::get_fdlimit Tries to find the current file descriptor limit and returns it, or @@ -2331,8 +2385,12 @@ C, C, C, -C or -C. +C, +C, +C, +C, +C or +C. If C<$fh> is C, then a file descriptor of C<-1> is passed. @@ -2481,7 +2539,8 @@ Please refer to L for more info on this call. The following C<$flags> values are available: C, -C and C. +C, C, +C and C. Example: create a new memfd.