… | |
… | |
12 | }; |
12 | }; |
13 | |
13 | |
14 | aio_unlink "/tmp/file", sub { }; |
14 | aio_unlink "/tmp/file", sub { }; |
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 | # Event |
20 | # Event |
21 | Event->io (fd => IO::AIO::poll_fileno, |
21 | Event->io (fd => IO::AIO::poll_fileno, |
22 | poll => 'r', async => 1, |
22 | poll => 'r', |
23 | cb => \&IO::AIO::poll_cb); |
23 | cb => \&IO::AIO::poll_cb); |
24 | |
24 | |
25 | # Glib/Gtk2 |
25 | # Glib/Gtk2 |
26 | add_watch Glib::IO IO::AIO::poll_fileno, |
26 | add_watch Glib::IO IO::AIO::poll_fileno, |
27 | \&IO::AIO::poll_cb; |
27 | \&IO::AIO::poll_cb; |
… | |
… | |
54 | use base 'Exporter'; |
54 | use base 'Exporter'; |
55 | |
55 | |
56 | use Fcntl (); |
56 | use Fcntl (); |
57 | |
57 | |
58 | BEGIN { |
58 | BEGIN { |
59 | $VERSION = 0.2; |
59 | $VERSION = 0.3; |
60 | |
60 | |
61 | @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat aio_unlink |
61 | @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat aio_unlink |
62 | aio_fsync aio_fdatasync aio_readahead); |
62 | aio_fsync aio_fdatasync aio_readahead); |
63 | @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel max_outstanding nreqs); |
63 | @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel max_outstanding nreqs); |
64 | |
64 | |
… | |
… | |
128 | |
128 | |
129 | Example: Read 15 bytes at offset 7 into scalar C<$buffer>, strating at |
129 | Example: Read 15 bytes at offset 7 into scalar C<$buffer>, strating at |
130 | offset C<0> within the scalar: |
130 | offset C<0> within the scalar: |
131 | |
131 | |
132 | aio_read $fh, 7, 15, $buffer, 0, sub { |
132 | aio_read $fh, 7, 15, $buffer, 0, sub { |
133 | $_[0] >= 0 or die "read error: $!"; |
133 | $_[0] > 0 or die "read error: $!"; |
134 | print "read <$buffer>\n"; |
134 | print "read $_[0] bytes: <$buffer>\n"; |
135 | }; |
135 | }; |
136 | |
136 | |
137 | =item aio_readahead $fh,$offset,$length, $callback |
137 | =item aio_readahead $fh,$offset,$length, $callback |
138 | |
138 | |
139 | Asynchronously reads the specified byte range into the page cache, using |
139 | Asynchronously reads the specified byte range into the page cache, using |