--- IO-AIO/README 2020/12/04 01:19:58 1.65 +++ IO-AIO/README 2022/09/05 00:04:07 1.68 @@ -230,6 +230,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 @@ -251,14 +252,21 @@ 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] + API NOTES All the "aio_*" calls are more or less thin wrappers around the syscall with the same name (sans "aio_"). The arguments are similar or @@ -1593,9 +1601,11 @@ 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 "aio_group" 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 "aio_group" 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: @@ -1610,10 +1620,11 @@ IO::AIO::flush; The call to "poll_cb" inside the loop will normally return - instantly, but as soon as more thna 32 reqeusts are in-flight, it - will block until some requests have been handled. This keeps the - loop from pushing a large number of "aio_stat" requests onto the - queue. + instantly, allowing the loop to progress, but as soon as more than + 32 requests are in-flight, it will block until some requests have + been handled. This keeps the loop from pushing a large number of + "aio_stat" requests onto the queue (which, with many paths to stat, + can use up a lot of memory). The default value for "max_outstanding" is very large, so there is no practical limit on the number of outstanding requests. @@ -1728,6 +1739,12 @@ "Asynchronous I/O" route. Many of these have an asynchronous "aio_*" counterpart. + $retval = IO::AIO::fexecve $fh, $argv, $envp + A more-or-less direct equivalent to the POSIX "fexecve" functions, + which allows you to specify the program to be executed via a file + descriptor (or handle). Returns -1 and sets errno to "ENOSYS" if not + available. + $numfd = IO::AIO::get_fdlimit Tries to find the current file descriptor limit and returns it, or "undef" and sets $! in case of an error. The limit is one larger @@ -1830,8 +1847,9 @@ "IO::AIO::MAP_LOCKED", "IO::AIO::MAP_NORESERVE", "IO::AIO::MAP_POPULATE", "IO::AIO::MAP_NONBLOCK", "IO::AIO::MAP_FIXED", "IO::AIO::MAP_GROWSDOWN", - "IO::AIO::MAP_32BIT", "IO::AIO::MAP_HUGETLB" or - "IO::AIO::MAP_STACK". + "IO::AIO::MAP_32BIT", "IO::AIO::MAP_HUGETLB", "IO::AIO::MAP_STACK", + "IO::AIO::MAP_FIXED_NOREPLACE", "IO::AIO::MAP_SHARED_VALIDATE", + "IO::AIO::MAP_SYNC" or "IO::AIO::MAP_UNINITIALIZED". If $fh is "undef", then a file descriptor of -1 is passed. @@ -1906,11 +1924,11 @@ To accept name-less sockets, use "undef" for $sockaddr and 0 for $sockaddr_maxlen. - The main reasons to use this syscall rather than portable - C«accept(2)> are that you can specify "SOCK_NONBLOCK" and/or - "SOCK_CLOEXEC" flags and you can accept name-less sockets by - specifying 0 for $sockaddr_maxlen, which is sadly not possible with - perl's interface to "accept". + The main reasons to use this syscall rather than portable accept(2) + are that you can specify "SOCK_NONBLOCK" and/or "SOCK_CLOEXEC" flags + and you can accept name-less sockets by specifying 0 for + $sockaddr_maxlen, which is sadly not possible with perl's interface + to "accept". IO::AIO::splice $r_fh, $r_off, $w_fh, $w_off, $length, $flags Calls the GNU/Linux splice(2) syscall, if available. If $r_off or @@ -1973,14 +1991,71 @@ Please refer to memfd_create(2) for more info on this call. The following $flags values are available: "IO::AIO::MFD_CLOEXEC", - "IO::AIO::MFD_ALLOW_SEALING" and "IO::AIO::MFD_HUGETLB". + "IO::AIO::MFD_ALLOW_SEALING", "IO::AIO::MFD_HUGETLB", + "IO::AIO::MFD_HUGETLB_2MB" and "IO::AIO::MFD_HUGETLB_1GB". Example: create a new memfd. my $fh = IO::AIO::memfd_create "somenameforprocfd", IO::AIO::MFD_CLOEXEC - or die "m,emfd_create: $!\n"; - =item $fh = IO::AIO::eventfd [$initval, [$flags]] + or die "memfd_create: $!\n"; + + $fh = IO::AIO::pidfd_open $pid[, $flags] + This is an interface to the Linux pidfd_open(2) system call. The + default for $flags is 0. + + On success, a new pidfd filehandle is returned (that is already set + to close-on-exec), otherwise returns "undef". If the syscall is + missing, fails with "ENOSYS". + + Example: open pid 6341 as pidfd. + + my $fh = IO::AIO::pidfd_open 6341 + or die "pidfd_open: $!\n"; + + $status = IO::AIO::pidfd_send_signal $pidfh, $signal[, $siginfo[, + $flags]] + This is an interface to the Linux pidfd_send_signal system call. The + default for $siginfo is "undef" and the default for $flags is 0. + + Returns the system call status. If the syscall is missing, fails + with "ENOSYS". + + When specified, $siginfo must be a reference to a hash with one or + more of the following members: + + code - the "si_code" member + pid - the "si_pid" member + uid - the "si_uid" member + value_int - the "si_value.sival_int" member + value_ptr - the "si_value.sival_ptr" member, specified as an integer + + Example: send a SIGKILL to the specified process. + + my $status = IO::AIO::pidfd_send_signal $pidfh, 9, undef + and die "pidfd_send_signal: $!\n"; + + Example: send a SIGKILL to the specified process with extra data. + + my $status = IO::AIO::pidfd_send_signal $pidfh, 9, { code => -1, value_int => 7 } + and die "pidfd_send_signal: $!\n"; + + $fh = IO::AIO::pidfd_getfd $pidfh, $targetfd[, $flags] + This is an interface to the Linux pidfd_getfd system call. The + default for $flags is 0. + + On success, returns a dup'ed copy of the target file descriptor + (specified as an integer) returned (that is already set to + close-on-exec), otherwise returns "undef". If the syscall is + missing, fails with "ENOSYS". + + Example: get a copy of standard error of another process and print + soemthing to it. + + my $errfh = IO::AIO::pidfd_getfd $pidfh, 2 + or die "pidfd_getfd: $!\n"; + print $errfh "stderr\n"; + $fh = IO::AIO::eventfd [$initval, [$flags]] This is a direct interface to the Linux eventfd(2) system call. The (unhelpful) defaults for $initval and $flags are 0 for both.