1 | NAME |
1 | NAME |
2 | IO::AIO - Asynchronous Input/Output |
2 | IO::AIO - Asynchronous Input/Output |
3 | |
3 | |
4 | SYNOPSIS |
4 | SYNOPSIS |
5 | use IO::AIO; |
5 | use IO::AIO; |
|
|
6 | |
|
|
7 | aio_open "/etc/passwd", O_RDONLY, 0, sub { |
|
|
8 | my ($fh) = @_; |
|
|
9 | ... |
|
|
10 | }; |
|
|
11 | |
|
|
12 | aio_unlink "/tmp/file", sub { }; |
|
|
13 | |
|
|
14 | aio_read $fh, 30000, 1024, $buffer, 0, sub { |
|
|
15 | $_[0] > 0 or die "read error: $!"; |
|
|
16 | }; |
|
|
17 | |
|
|
18 | # Event |
|
|
19 | Event->io (fd => IO::AIO::poll_fileno, |
|
|
20 | poll => 'r', |
|
|
21 | cb => \&IO::AIO::poll_cb); |
|
|
22 | |
|
|
23 | # Glib/Gtk2 |
|
|
24 | add_watch Glib::IO IO::AIO::poll_fileno, |
|
|
25 | \&IO::AIO::poll_cb; |
|
|
26 | |
|
|
27 | # Tk |
|
|
28 | Tk::Event::IO->fileevent (IO::AIO::poll_fileno, "", |
|
|
29 | readable => \&IO::AIO::poll_cb); |
6 | |
30 | |
7 | DESCRIPTION |
31 | DESCRIPTION |
8 | This module implements asynchronous I/O using whatever means your |
32 | This module implements asynchronous I/O using whatever means your |
9 | operating system supports. |
33 | operating system supports. |
10 | |
34 | |
… | |
… | |
76 | |
100 | |
77 | Example: Read 15 bytes at offset 7 into scalar $buffer, strating at |
101 | Example: Read 15 bytes at offset 7 into scalar $buffer, strating at |
78 | offset 0 within the scalar: |
102 | offset 0 within the scalar: |
79 | |
103 | |
80 | aio_read $fh, 7, 15, $buffer, 0, sub { |
104 | aio_read $fh, 7, 15, $buffer, 0, sub { |
81 | $_[0] >= 0 or die "read error: $!"; |
105 | $_[0] > 0 or die "read error: $!"; |
82 | print "read <$buffer>\n"; |
106 | print "read $_[0] bytes: <$buffer>\n"; |
83 | }; |
107 | }; |
84 | |
108 | |
85 | aio_readahead $fh,$offset,$length, $callback |
109 | aio_readahead $fh,$offset,$length, $callback |
86 | Asynchronously reads the specified byte range into the page cache, |
110 | Asynchronously reads the specified byte range into the page cache, |
87 | using the "readahead" syscall. If that syscall doesn't exist the |
111 | using the "readahead" syscall. If that syscall doesn't exist the |