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.55 by root, Sun Oct 22 00:49:29 2006 UTC vs.
Revision 1.57 by root, Sun Oct 22 01:28:31 2006 UTC

15 15
16 aio_read $fh, 30000, 1024, $buffer, 0, sub { 16 aio_read $fh, 30000, 1024, $buffer, 0, sub {
17 $_[0] > 0 or die "read error: $!"; 17 $_[0] > 0 or die "read error: $!";
18 }; 18 };
19 19
20 use IO::AIO 2; # version has aio objects 20 # version 2+ has request and group objects
21 use IO::AIO 2;
21 22
22 my $req = aio_unlink "/tmp/file", sub { }; 23 my $req = aio_unlink "/tmp/file", sub { };
23 $req->cancel; # cancel request if still in queue 24 $req->cancel; # cancel request if still in queue
24 25
25 # AnyEvent 26 my $grp = aio_group sub { print "all stats done\n" };
27 add $grp aio_stat "..." for ...;
28
29 # AnyEvent integration
26 open my $fh, "<&=" . IO::AIO::poll_fileno or die "$!"; 30 open my $fh, "<&=" . IO::AIO::poll_fileno or die "$!";
27 my $w = AnyEvent->io (fh => $fh, poll => 'r', cb => sub { IO::AIO::poll_cb }); 31 my $w = AnyEvent->io (fh => $fh, poll => 'r', cb => sub { IO::AIO::poll_cb });
28 32
29 # Event 33 # Event integration
30 Event->io (fd => IO::AIO::poll_fileno, 34 Event->io (fd => IO::AIO::poll_fileno,
31 poll => 'r', 35 poll => 'r',
32 cb => \&IO::AIO::poll_cb); 36 cb => \&IO::AIO::poll_cb);
33 37
34 # Glib/Gtk2 38 # Glib/Gtk2 integration
35 add_watch Glib::IO IO::AIO::poll_fileno, 39 add_watch Glib::IO IO::AIO::poll_fileno,
36 in => sub { IO::AIO::poll_cb; 1 }; 40 in => sub { IO::AIO::poll_cb; 1 };
37 41
38 # Tk 42 # Tk integration
39 Tk::Event::IO->fileevent (IO::AIO::poll_fileno, "", 43 Tk::Event::IO->fileevent (IO::AIO::poll_fileno, "",
40 readable => \&IO::AIO::poll_cb); 44 readable => \&IO::AIO::poll_cb);
41 45
42 # Danga::Socket 46 # Danga::Socket integration
43 Danga::Socket->AddOtherFds (IO::AIO::poll_fileno => 47 Danga::Socket->AddOtherFds (IO::AIO::poll_fileno =>
44 \&IO::AIO::poll_cb); 48 \&IO::AIO::poll_cb);
45
46 49
47=head1 DESCRIPTION 50=head1 DESCRIPTION
48 51
49This module implements asynchronous I/O using whatever means your 52This module implements asynchronous I/O using whatever means your
50operating system supports. 53operating system supports.
524 add $grp 527 add $grp
525 (aio_stat ...), 528 (aio_stat ...),
526 (aio_stat ...), 529 (aio_stat ...),
527 ...; 530 ...;
528 531
529=item aio_sleep $fractional_seconds, $callback->() *NOT EXPORTED* 532=item IO::AIO::aio_sleep $fractional_seconds, $callback->() *NOT EXPORTED*
530 533
531Mainly used for debugging and benchmarking, this aio request puts one of 534Mainly used for debugging and benchmarking, this aio request puts one of
532the request workers to sleep for the given time. 535the request workers to sleep for the given time.
536
537While it is theoretically handy to have simple I/O scheduling requests
538like sleep and file handle readable/writable, the overhead this creates
539is immense, so do not use this function except to put your application
540under artificial I/O pressure.
533 541
534=back 542=back
535 543
536=head2 IO::AIO::REQ CLASS 544=head2 IO::AIO::REQ CLASS
537 545
595Their lifetime, simplified, looks like this: when they are empty, they 603Their lifetime, simplified, looks like this: when they are empty, they
596will finish very quickly. If they contain only requests that are in the 604will finish very quickly. If they contain only requests that are in the
597C<done> state, they will also finish. Otherwise they will continue to 605C<done> state, they will also finish. Otherwise they will continue to
598exist. 606exist.
599 607
608That means after creating a group you have some time to add requests. And
609in the callbacks of those requests, you can add further requests to the
610group. And only when all those requests have finished will the the group
611itself finish.
612
600=over 4 613=over 4
601 614
602=item $grp->add (...) 615=item $grp->add (...)
603 616
604=item add $grp ... 617=item add $grp ...
605 618
606Add one or more 619Add one or more requests to the group. Any type of L<IO::AIO::REQ> can
607Cancels the request, if possible. Has the effect of skipping execution 620be added, including other groups, as long as you do not create circular
608when entering the B<execute> state and skipping calling the callback when 621dependencies.
609entering the the B<result> state, but will leave the request otherwise 622
610untouched. That means that requests that currently execute will not be 623Returns all its arguments.
611stopped and resources held by the request will not be freed prematurely.
612 624
613=back 625=back
614 626
615=head2 SUPPORT FUNCTIONS 627=head2 SUPPORT FUNCTIONS
616 628

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines