… | |
… | |
3 | |
3 | |
4 | SYNOPSIS |
4 | SYNOPSIS |
5 | use IO::AIO; |
5 | use IO::AIO; |
6 | |
6 | |
7 | aio_open "/etc/passwd", O_RDONLY, 0, sub { |
7 | aio_open "/etc/passwd", O_RDONLY, 0, sub { |
8 | my ($fh) = @_; |
8 | my $fh = shift |
|
|
9 | or die "/etc/passwd: $!"; |
9 | ... |
10 | ... |
10 | }; |
11 | }; |
11 | |
12 | |
12 | aio_unlink "/tmp/file", sub { }; |
13 | aio_unlink "/tmp/file", sub { }; |
13 | |
14 | |
… | |
… | |
95 | poll => 'r', |
96 | poll => 'r', |
96 | cb => \&IO::AIO::poll_cb); |
97 | cb => \&IO::AIO::poll_cb); |
97 | |
98 | |
98 | # queue the request to open /etc/passwd |
99 | # queue the request to open /etc/passwd |
99 | aio_open "/etc/passwd", O_RDONLY, 0, sub { |
100 | aio_open "/etc/passwd", O_RDONLY, 0, sub { |
100 | my $fh = $_[0] |
101 | my $fh = shift |
101 | or die "error while opening: $!"; |
102 | or die "error while opening: $!"; |
102 | |
103 | |
103 | # stat'ing filehandles is generally non-blocking |
104 | # stat'ing filehandles is generally non-blocking |
104 | my $size = -s $fh; |
105 | my $size = -s $fh; |
105 | |
106 | |
… | |
… | |
241 | They are the same as used by "sysopen". |
242 | They are the same as used by "sysopen". |
242 | |
243 | |
243 | Likewise, $mode specifies the mode of the newly created file, if it |
244 | Likewise, $mode specifies the mode of the newly created file, if it |
244 | didn't exist and "O_CREAT" has been given, just like perl's |
245 | didn't exist and "O_CREAT" has been given, just like perl's |
245 | "sysopen", except that it is mandatory (i.e. use 0 if you don't |
246 | "sysopen", except that it is mandatory (i.e. use 0 if you don't |
246 | create new files, and 0666 or 0777 if you do). |
247 | create new files, and 0666 or 0777 if you do). Note that the $mode |
|
|
248 | will be modified by the umask in effect then the request is being |
|
|
249 | executed, so better never change the umask. |
247 | |
250 | |
248 | Example: |
251 | Example: |
249 | |
252 | |
250 | aio_open "/etc/passwd", O_RDONLY, 0, sub { |
253 | aio_open "/etc/passwd", O_RDONLY, 0, sub { |
251 | if ($_[0]) { |
254 | if ($_[0]) { |
… | |
… | |
372 | |
375 | |
373 | aio_rename $srcpath, $dstpath, $callback->($status) |
376 | aio_rename $srcpath, $dstpath, $callback->($status) |
374 | Asynchronously rename the object at $srcpath to $dstpath, just as |
377 | Asynchronously rename the object at $srcpath to $dstpath, just as |
375 | rename(2) and call the callback with the result code. |
378 | rename(2) and call the callback with the result code. |
376 | |
379 | |
|
|
380 | aio_mkdir $pathname, $mode, $callback->($status) |
|
|
381 | Asynchronously mkdir (create) a directory and call the callback with |
|
|
382 | the result code. $mode will be modified by the umask at the time the |
|
|
383 | request is executed, so do not change your umask. |
|
|
384 | |
377 | aio_rmdir $pathname, $callback->($status) |
385 | aio_rmdir $pathname, $callback->($status) |
378 | Asynchronously rmdir (delete) a directory and call the callback with |
386 | Asynchronously rmdir (delete) a directory and call the callback with |
379 | the result code. |
387 | the result code. |
380 | |
388 | |
381 | aio_readdir $pathname, $callback->($entries) |
389 | aio_readdir $pathname, $callback->($entries) |
… | |
… | |
383 | entire directory (i.e. opendir + readdir + closedir). The entries |
391 | entire directory (i.e. opendir + readdir + closedir). The entries |
384 | will not be sorted, and will NOT include the "." and ".." entries. |
392 | will not be sorted, and will NOT include the "." and ".." entries. |
385 | |
393 | |
386 | The callback a single argument which is either "undef" or an |
394 | The callback a single argument which is either "undef" or an |
387 | array-ref with the filenames. |
395 | array-ref with the filenames. |
|
|
396 | |
|
|
397 | aio_load $path, $data, $callback->($status) |
|
|
398 | This is a composite request that tries to fully load the given file |
|
|
399 | into memory. Status is the same as with aio_read. |
388 | |
400 | |
389 | aio_copy $srcpath, $dstpath, $callback->($status) |
401 | aio_copy $srcpath, $dstpath, $callback->($status) |
390 | Try to copy the *file* (directories not supported as either source |
402 | Try to copy the *file* (directories not supported as either source |
391 | or destination) from $srcpath to $dstpath and call the callback with |
403 | or destination) from $srcpath to $dstpath and call the callback with |
392 | the 0 (error) or -1 ok. |
404 | the 0 (error) or -1 ok. |
… | |
… | |
460 | |
472 | |
461 | It will also likely work on non-POSIX filesystems with reduced |
473 | It will also likely work on non-POSIX filesystems with reduced |
462 | efficiency as those tend to return 0 or 1 as link counts, which |
474 | efficiency as those tend to return 0 or 1 as link counts, which |
463 | disables the directory counting heuristic. |
475 | disables the directory counting heuristic. |
464 | |
476 | |
|
|
477 | aio_rmtree $path, $callback->($status) |
|
|
478 | Delete a directory tree starting (and including) $path, return the |
|
|
479 | status of the final "rmdir" only. This is a composite request that |
|
|
480 | uses "aio_scandir" to recurse into and rmdir directories, and unlink |
|
|
481 | everything else. |
|
|
482 | |
465 | aio_fsync $fh, $callback->($status) |
483 | aio_fsync $fh, $callback->($status) |
466 | Asynchronously call fsync on the given filehandle and call the |
484 | Asynchronously call fsync on the given filehandle and call the |
467 | callback with the fsync result code. |
485 | callback with the fsync result code. |
468 | |
486 | |
469 | aio_fdatasync $fh, $callback->($status) |
487 | aio_fdatasync $fh, $callback->($status) |
… | |
… | |
711 | Event->io (fd => IO::AIO::poll_fileno, |
729 | Event->io (fd => IO::AIO::poll_fileno, |
712 | poll => 'r', nice => 1, |
730 | poll => 'r', nice => 1, |
713 | cb => &IO::AIO::poll_cb); |
731 | cb => &IO::AIO::poll_cb); |
714 | |
732 | |
715 | IO::AIO::poll_wait |
733 | IO::AIO::poll_wait |
|
|
734 | If there are any outstanding requests and none of them in the result |
716 | Wait till the result filehandle becomes ready for reading (simply |
735 | phase, wait till the result filehandle becomes ready for reading |
717 | does a "select" on the filehandle. This is useful if you want to |
736 | (simply does a "select" on the filehandle. This is useful if you |
718 | synchronously wait for some requests to finish). |
737 | want to synchronously wait for some requests to finish). |
719 | |
738 | |
720 | See "nreqs" for an example. |
739 | See "nreqs" for an example. |
721 | |
740 | |
722 | IO::AIO::poll |
741 | IO::AIO::poll |
723 | Waits until some requests have been handled. |
742 | Waits until some requests have been handled. |
724 | |
743 | |
|
|
744 | Returns the number of requests processed, but is otherwise strictly |
725 | Strictly equivalent to: |
745 | equivalent to: |
726 | |
746 | |
727 | IO::AIO::poll_wait, IO::AIO::poll_cb |
747 | IO::AIO::poll_wait, IO::AIO::poll_cb |
728 | if IO::AIO::nreqs; |
|
|
729 | |
748 | |
730 | IO::AIO::flush |
749 | IO::AIO::flush |
731 | Wait till all outstanding AIO requests have been handled. |
750 | Wait till all outstanding AIO requests have been handled. |
732 | |
751 | |
733 | Strictly equivalent to: |
752 | Strictly equivalent to: |