… | |
… | |
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 | |
49 | This module implements asynchronous I/O using whatever means your |
52 | This module implements asynchronous I/O using whatever means your |
50 | operating system supports. |
53 | operating 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 | |
531 | Mainly used for debugging and benchmarking, this aio request puts one of |
534 | Mainly used for debugging and benchmarking, this aio request puts one of |
532 | the request workers to sleep for the given time. |
535 | the request workers to sleep for the given time. |
|
|
536 | |
|
|
537 | While it is theoretically handy to have simple I/O scheduling requests |
|
|
538 | like sleep and file handle readable/writable, the overhead this creates |
|
|
539 | is immense, so do not use this function except to put your application |
|
|
540 | under 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 | |