… | |
… | |
26 | $req->cancel; # cancel request if still in queue |
26 | $req->cancel; # cancel request if still in queue |
27 | |
27 | |
28 | my $grp = aio_group sub { print "all stats done\n" }; |
28 | my $grp = aio_group sub { print "all stats done\n" }; |
29 | add $grp aio_stat "..." for ...; |
29 | add $grp aio_stat "..." for ...; |
30 | |
30 | |
31 | # AnyEvent integration (EV, Event, Glib, Tk, urxvt, pureperl...) |
31 | # AnyEvent integration (EV, Event, Glib, Tk, POE, urxvt, pureperl...) |
32 | open my $fh, "<&=" . IO::AIO::poll_fileno or die "$!"; |
32 | use AnyEvent::AIO; |
33 | my $w = AnyEvent->io (fh => $fh, poll => 'r', cb => sub { IO::AIO::poll_cb }); |
|
|
34 | |
33 | |
35 | # EV integration |
34 | # EV integration |
36 | my $w = EV::io IO::AIO::poll_fileno, EV::READ, \&IO::AIO::poll_cb; |
35 | my $w = EV::io IO::AIO::poll_fileno, EV::READ, \&IO::AIO::poll_cb; |
37 | |
36 | |
38 | # Event integration |
37 | # Event integration |
… | |
… | |
194 | use strict 'vars'; |
193 | use strict 'vars'; |
195 | |
194 | |
196 | use base 'Exporter'; |
195 | use base 'Exporter'; |
197 | |
196 | |
198 | BEGIN { |
197 | BEGIN { |
199 | our $VERSION = '3.0'; |
198 | our $VERSION = '3.1'; |
200 | |
199 | |
201 | our @AIO_REQ = qw(aio_sendfile aio_read aio_write aio_open aio_close |
200 | our @AIO_REQ = qw(aio_sendfile aio_read aio_write aio_open aio_close |
202 | aio_stat aio_lstat aio_unlink aio_rmdir aio_readdir |
201 | aio_stat aio_lstat aio_unlink aio_rmdir aio_readdir |
203 | aio_scandir aio_symlink aio_readlink aio_sync aio_fsync |
202 | aio_scandir aio_symlink aio_readlink aio_sync aio_fsync |
204 | aio_fdatasync aio_pathsync aio_readahead |
203 | aio_fdatasync aio_pathsync aio_readahead |
… | |
… | |
225 | All the C<aio_*> calls are more or less thin wrappers around the syscall |
224 | All the C<aio_*> calls are more or less thin wrappers around the syscall |
226 | with the same name (sans C<aio_>). The arguments are similar or identical, |
225 | with the same name (sans C<aio_>). The arguments are similar or identical, |
227 | and they all accept an additional (and optional) C<$callback> argument |
226 | and they all accept an additional (and optional) C<$callback> argument |
228 | which must be a code reference. This code reference will get called with |
227 | which must be a code reference. This code reference will get called with |
229 | the syscall return code (e.g. most syscalls return C<-1> on error, unlike |
228 | the syscall return code (e.g. most syscalls return C<-1> on error, unlike |
230 | perl, which usually delivers "false") as it's sole argument when the given |
229 | perl, which usually delivers "false") as its sole argument after the given |
231 | syscall has been executed asynchronously. |
230 | syscall has been executed asynchronously. |
232 | |
231 | |
233 | All functions expecting a filehandle keep a copy of the filehandle |
232 | All functions expecting a filehandle keep a copy of the filehandle |
234 | internally until the request has finished. |
233 | internally until the request has finished. |
235 | |
234 | |
… | |
… | |
249 | your pathnames to the locale (or other) encoding in effect in the user |
248 | your pathnames to the locale (or other) encoding in effect in the user |
250 | environment, d) use Glib::filename_from_unicode on unicode filenames or e) |
249 | environment, d) use Glib::filename_from_unicode on unicode filenames or e) |
251 | use something else to ensure your scalar has the correct contents. |
250 | use something else to ensure your scalar has the correct contents. |
252 | |
251 | |
253 | This works, btw. independent of the internal UTF-8 bit, which IO::AIO |
252 | This works, btw. independent of the internal UTF-8 bit, which IO::AIO |
254 | handles correctly wether it is set or not. |
253 | handles correctly whether it is set or not. |
255 | |
254 | |
256 | =over 4 |
255 | =over 4 |
257 | |
256 | |
258 | =item $prev_pri = aioreq_pri [$pri] |
257 | =item $prev_pri = aioreq_pri [$pri] |
259 | |
258 | |
… | |
… | |
566 | |
565 | |
567 | Try to copy the I<file> (directories not supported as either source or |
566 | Try to copy the I<file> (directories not supported as either source or |
568 | destination) from C<$srcpath> to C<$dstpath> and call the callback with |
567 | destination) from C<$srcpath> to C<$dstpath> and call the callback with |
569 | the C<0> (error) or C<-1> ok. |
568 | the C<0> (error) or C<-1> ok. |
570 | |
569 | |
571 | This is a composite request that it creates the destination file with |
570 | This is a composite request that creates the destination file with |
572 | mode 0200 and copies the contents of the source file into it using |
571 | mode 0200 and copies the contents of the source file into it using |
573 | C<aio_sendfile>, followed by restoring atime, mtime, access mode and |
572 | C<aio_sendfile>, followed by restoring atime, mtime, access mode and |
574 | uid/gid, in that order. |
573 | uid/gid, in that order. |
575 | |
574 | |
576 | If an error occurs, the partial destination file will be unlinked, if |
575 | If an error occurs, the partial destination file will be unlinked, if |
… | |
… | |
632 | |
631 | |
633 | Try to move the I<file> (directories not supported as either source or |
632 | Try to move the I<file> (directories not supported as either source or |
634 | destination) from C<$srcpath> to C<$dstpath> and call the callback with |
633 | destination) from C<$srcpath> to C<$dstpath> and call the callback with |
635 | the C<0> (error) or C<-1> ok. |
634 | the C<0> (error) or C<-1> ok. |
636 | |
635 | |
637 | This is a composite request that tries to rename(2) the file first. If |
636 | This is a composite request that tries to rename(2) the file first; if |
638 | rename files with C<EXDEV>, it copies the file with C<aio_copy> and, if |
637 | rename fails with C<EXDEV>, it copies the file with C<aio_copy> and, if |
639 | that is successful, unlinking the C<$srcpath>. |
638 | that is successful, unlinks the C<$srcpath>. |
640 | |
639 | |
641 | =cut |
640 | =cut |
642 | |
641 | |
643 | sub aio_move($$;$) { |
642 | sub aio_move($$;$) { |
644 | my ($src, $dst, $cb) = @_; |
643 | my ($src, $dst, $cb) = @_; |
… | |
… | |
859 | detected, it will be emulated by calling C<fsync> instead. |
858 | detected, it will be emulated by calling C<fsync> instead. |
860 | |
859 | |
861 | =item aio_pathsync $path, $callback->($status) |
860 | =item aio_pathsync $path, $callback->($status) |
862 | |
861 | |
863 | This request tries to open, fsync and close the given path. This is a |
862 | This request tries to open, fsync and close the given path. This is a |
864 | composite request intended tosync directories after directory operations |
863 | composite request intended to sync directories after directory operations |
865 | (E.g. rename). This might not work on all operating systems or have any |
864 | (E.g. rename). This might not work on all operating systems or have any |
866 | specific effect, but usually it makes sure that directory changes get |
865 | specific effect, but usually it makes sure that directory changes get |
867 | written to disc. It works for anything that can be opened for read-only, |
866 | written to disc. It works for anything that can be opened for read-only, |
868 | not just directories. |
867 | not just directories. |
869 | |
868 | |
… | |
… | |
1014 | Their lifetime, simplified, looks like this: when they are empty, they |
1013 | Their lifetime, simplified, looks like this: when they are empty, they |
1015 | will finish very quickly. If they contain only requests that are in the |
1014 | will finish very quickly. If they contain only requests that are in the |
1016 | C<done> state, they will also finish. Otherwise they will continue to |
1015 | C<done> state, they will also finish. Otherwise they will continue to |
1017 | exist. |
1016 | exist. |
1018 | |
1017 | |
1019 | That means after creating a group you have some time to add requests. And |
1018 | That means after creating a group you have some time to add requests |
1020 | in the callbacks of those requests, you can add further requests to the |
1019 | (precisely before the callback has been invoked, which is only done within |
1021 | group. And only when all those requests have finished will the the group |
1020 | the C<poll_cb>). And in the callbacks of those requests, you can add |
1022 | itself finish. |
1021 | further requests to the group. And only when all those requests have |
|
|
1022 | finished will the the group itself finish. |
1023 | |
1023 | |
1024 | =over 4 |
1024 | =over 4 |
1025 | |
1025 | |
1026 | =item add $grp ... |
1026 | =item add $grp ... |
1027 | |
1027 | |
… | |
… | |
1076 | not impose any limits). |
1076 | not impose any limits). |
1077 | |
1077 | |
1078 | If the feed does not queue more requests when called, it will be |
1078 | If the feed does not queue more requests when called, it will be |
1079 | automatically removed from the group. |
1079 | automatically removed from the group. |
1080 | |
1080 | |
1081 | If the feed limit is C<0>, it will be set to C<2> automatically. |
1081 | If the feed limit is C<0> when this method is called, it will be set to |
|
|
1082 | C<2> automatically. |
1082 | |
1083 | |
1083 | Example: |
1084 | Example: |
1084 | |
1085 | |
1085 | # stat all files in @files, but only ever use four aio requests concurrently: |
1086 | # stat all files in @files, but only ever use four aio requests concurrently: |
1086 | |
1087 | |
… | |
… | |
1098 | Sets the feeder limit for the group: The feeder will be called whenever |
1099 | Sets the feeder limit for the group: The feeder will be called whenever |
1099 | the group contains less than this many requests. |
1100 | the group contains less than this many requests. |
1100 | |
1101 | |
1101 | Setting the limit to C<0> will pause the feeding process. |
1102 | Setting the limit to C<0> will pause the feeding process. |
1102 | |
1103 | |
|
|
1104 | The default value for the limit is C<0>, but note that setting a feeder |
|
|
1105 | automatically bumps it up to C<2>. |
|
|
1106 | |
1103 | =back |
1107 | =back |
1104 | |
1108 | |
1105 | =head2 SUPPORT FUNCTIONS |
1109 | =head2 SUPPORT FUNCTIONS |
1106 | |
1110 | |
1107 | =head3 EVENT PROCESSING AND EVENT LOOP INTEGRATION |
1111 | =head3 EVENT PROCESSING AND EVENT LOOP INTEGRATION |
… | |
… | |
1118 | See C<poll_cb> for an example. |
1122 | See C<poll_cb> for an example. |
1119 | |
1123 | |
1120 | =item IO::AIO::poll_cb |
1124 | =item IO::AIO::poll_cb |
1121 | |
1125 | |
1122 | Process some outstanding events on the result pipe. You have to call this |
1126 | Process some outstanding events on the result pipe. You have to call this |
1123 | regularly. Returns the number of events processed. Returns immediately |
1127 | regularly. Returns C<0> if all events could be processed, or C<-1> if it |
|
|
1128 | returned earlier for whatever reason. Returns immediately when no events |
1124 | when no events are outstanding. The amount of events processed depends on |
1129 | are outstanding. The amount of events processed depends on the settings of |
1125 | the settings of C<IO::AIO::max_poll_req> and C<IO::AIO::max_poll_time>. |
1130 | C<IO::AIO::max_poll_req> and C<IO::AIO::max_poll_time>. |
1126 | |
1131 | |
1127 | If not all requests were processed for whatever reason, the filehandle |
1132 | If not all requests were processed for whatever reason, the filehandle |
1128 | will still be ready when C<poll_cb> returns. |
1133 | will still be ready when C<poll_cb> returns, so normally you don't have to |
|
|
1134 | do anything special to have it called later. |
1129 | |
1135 | |
1130 | Example: Install an Event watcher that automatically calls |
1136 | Example: Install an Event watcher that automatically calls |
1131 | IO::AIO::poll_cb with high priority: |
1137 | IO::AIO::poll_cb with high priority: |
1132 | |
1138 | |
1133 | Event->io (fd => IO::AIO::poll_fileno, |
1139 | Event->io (fd => IO::AIO::poll_fileno, |
… | |
… | |
1342 | |
1348 | |
1343 | Known bugs will be fixed in the next release. |
1349 | Known bugs will be fixed in the next release. |
1344 | |
1350 | |
1345 | =head1 SEE ALSO |
1351 | =head1 SEE ALSO |
1346 | |
1352 | |
1347 | L<Coro::AIO>. |
1353 | L<AnyEvent::AIO> for easy integration into event loops, L<Coro::AIO> for a |
|
|
1354 | more natural syntax. |
1348 | |
1355 | |
1349 | =head1 AUTHOR |
1356 | =head1 AUTHOR |
1350 | |
1357 | |
1351 | Marc Lehmann <schmorp@schmorp.de> |
1358 | Marc Lehmann <schmorp@schmorp.de> |
1352 | http://home.schmorp.de/ |
1359 | http://home.schmorp.de/ |