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

Comparing IO-AIO/AIO.pm (file contents):
Revision 1.124 by root, Sat May 10 19:25:33 2008 UTC vs.
Revision 1.137 by root, Sun Oct 5 16:56:08 2008 UTC

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
194use strict 'vars'; 193use strict 'vars';
195 194
196use base 'Exporter'; 195use base 'Exporter';
197 196
198BEGIN { 197BEGIN {
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
225All the C<aio_*> calls are more or less thin wrappers around the syscall 224All the C<aio_*> calls are more or less thin wrappers around the syscall
226with the same name (sans C<aio_>). The arguments are similar or identical, 225with the same name (sans C<aio_>). The arguments are similar or identical,
227and they all accept an additional (and optional) C<$callback> argument 226and they all accept an additional (and optional) C<$callback> argument
228which must be a code reference. This code reference will get called with 227which must be a code reference. This code reference will get called with
229the syscall return code (e.g. most syscalls return C<-1> on error, unlike 228the syscall return code (e.g. most syscalls return C<-1> on error, unlike
230perl, which usually delivers "false") as it's sole argument when the given 229perl, which usually delivers "false") as its sole argument after the given
231syscall has been executed asynchronously. 230syscall has been executed asynchronously.
232 231
233All functions expecting a filehandle keep a copy of the filehandle 232All functions expecting a filehandle keep a copy of the filehandle
234internally until the request has finished. 233internally until the request has finished.
235 234
249your pathnames to the locale (or other) encoding in effect in the user 248your pathnames to the locale (or other) encoding in effect in the user
250environment, d) use Glib::filename_from_unicode on unicode filenames or e) 249environment, d) use Glib::filename_from_unicode on unicode filenames or e)
251use something else to ensure your scalar has the correct contents. 250use something else to ensure your scalar has the correct contents.
252 251
253This works, btw. independent of the internal UTF-8 bit, which IO::AIO 252This works, btw. independent of the internal UTF-8 bit, which IO::AIO
254handles correctly wether it is set or not. 253handles 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
567Try to copy the I<file> (directories not supported as either source or 566Try to copy the I<file> (directories not supported as either source or
568destination) from C<$srcpath> to C<$dstpath> and call the callback with 567destination) from C<$srcpath> to C<$dstpath> and call the callback with
569the C<0> (error) or C<-1> ok. 568the C<0> (error) or C<-1> ok.
570 569
571This is a composite request that it creates the destination file with 570This is a composite request that creates the destination file with
572mode 0200 and copies the contents of the source file into it using 571mode 0200 and copies the contents of the source file into it using
573C<aio_sendfile>, followed by restoring atime, mtime, access mode and 572C<aio_sendfile>, followed by restoring atime, mtime, access mode and
574uid/gid, in that order. 573uid/gid, in that order.
575 574
576If an error occurs, the partial destination file will be unlinked, if 575If an error occurs, the partial destination file will be unlinked, if
632 631
633Try to move the I<file> (directories not supported as either source or 632Try to move the I<file> (directories not supported as either source or
634destination) from C<$srcpath> to C<$dstpath> and call the callback with 633destination) from C<$srcpath> to C<$dstpath> and call the callback with
635the C<0> (error) or C<-1> ok. 634the C<0> (error) or C<-1> ok.
636 635
637This is a composite request that tries to rename(2) the file first. If 636This is a composite request that tries to rename(2) the file first; if
638rename files with C<EXDEV>, it copies the file with C<aio_copy> and, if 637rename fails with C<EXDEV>, it copies the file with C<aio_copy> and, if
639that is successful, unlinking the C<$srcpath>. 638that is successful, unlinks the C<$srcpath>.
640 639
641=cut 640=cut
642 641
643sub aio_move($$;$) { 642sub aio_move($$;$) {
644 my ($src, $dst, $cb) = @_; 643 my ($src, $dst, $cb) = @_;
859detected, it will be emulated by calling C<fsync> instead. 858detected, 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
863This request tries to open, fsync and close the given path. This is a 862This request tries to open, fsync and close the given path. This is a
864composite request intended tosync directories after directory operations 863composite 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
866specific effect, but usually it makes sure that directory changes get 865specific effect, but usually it makes sure that directory changes get
867written to disc. It works for anything that can be opened for read-only, 866written to disc. It works for anything that can be opened for read-only,
868not just directories. 867not just directories.
869 868
1014Their lifetime, simplified, looks like this: when they are empty, they 1013Their lifetime, simplified, looks like this: when they are empty, they
1015will finish very quickly. If they contain only requests that are in the 1014will finish very quickly. If they contain only requests that are in the
1016C<done> state, they will also finish. Otherwise they will continue to 1015C<done> state, they will also finish. Otherwise they will continue to
1017exist. 1016exist.
1018 1017
1019That means after creating a group you have some time to add requests. And 1018That means after creating a group you have some time to add requests
1020in 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
1021group. And only when all those requests have finished will the the group 1020the C<poll_cb>). And in the callbacks of those requests, you can add
1022itself finish. 1021further requests to the group. And only when all those requests have
1022finished 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
1118See C<poll_cb> for an example. 1118See C<poll_cb> for an example.
1119 1119
1120=item IO::AIO::poll_cb 1120=item IO::AIO::poll_cb
1121 1121
1122Process some outstanding events on the result pipe. You have to call this 1122Process some outstanding events on the result pipe. You have to call this
1123regularly. Returns the number of events processed. Returns immediately 1123regularly. Returns C<0> if all events could be processed, or C<-1> if it
1124returned earlier for whatever reason. Returns immediately when no events
1124when no events are outstanding. The amount of events processed depends on 1125are outstanding. The amount of events processed depends on the settings of
1125the settings of C<IO::AIO::max_poll_req> and C<IO::AIO::max_poll_time>. 1126C<IO::AIO::max_poll_req> and C<IO::AIO::max_poll_time>.
1126 1127
1127If not all requests were processed for whatever reason, the filehandle 1128If not all requests were processed for whatever reason, the filehandle
1128will still be ready when C<poll_cb> returns. 1129will still be ready when C<poll_cb> returns, so normally you don't have to
1130do anything special to have it called later.
1129 1131
1130Example: Install an Event watcher that automatically calls 1132Example: Install an Event watcher that automatically calls
1131IO::AIO::poll_cb with high priority: 1133IO::AIO::poll_cb with high priority:
1132 1134
1133 Event->io (fd => IO::AIO::poll_fileno, 1135 Event->io (fd => IO::AIO::poll_fileno,
1342 1344
1343Known bugs will be fixed in the next release. 1345Known bugs will be fixed in the next release.
1344 1346
1345=head1 SEE ALSO 1347=head1 SEE ALSO
1346 1348
1347L<Coro::AIO>. 1349L<AnyEvent::AIO> for easy integration into event loops, L<Coro::AIO> for a
1350more natural syntax.
1348 1351
1349=head1 AUTHOR 1352=head1 AUTHOR
1350 1353
1351 Marc Lehmann <schmorp@schmorp.de> 1354 Marc Lehmann <schmorp@schmorp.de>
1352 http://home.schmorp.de/ 1355 http://home.schmorp.de/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines