… | |
… | |
4 | |
4 | |
5 | =head1 SYNOPSIS |
5 | =head1 SYNOPSIS |
6 | |
6 | |
7 | use Linux::AIO; |
7 | use Linux::AIO; |
8 | |
8 | |
|
|
9 | # This module has been mostly superseded by IO::AIO. |
|
|
10 | |
9 | =head1 DESCRIPTION |
11 | =head1 DESCRIPTION |
|
|
12 | |
|
|
13 | I<This module has been mostly superseded by IO::AIO, which is API |
|
|
14 | compatible.> |
10 | |
15 | |
11 | This module implements asynchronous I/O using the means available to Linux |
16 | This module implements asynchronous I/O using the means available to Linux |
12 | - clone. It does not hook into the POSIX aio_* functions because Linux |
17 | - clone. It does not hook into the POSIX aio_* functions because Linux |
13 | does not yet support these in the kernel (even as of 2.6.12, only O_DIRECT |
18 | does not yet support these in the kernel (even as of 2.6.12, only O_DIRECT |
14 | files are supported) and even if, it would only allow aio_read and write, |
19 | files are supported) and even if, it would only allow aio_read and write, |
… | |
… | |
39 | All functions that expect a filehandle will also accept a file descriptor. |
44 | All functions that expect a filehandle will also accept a file descriptor. |
40 | |
45 | |
41 | The filenames you pass to these routines I<must> be absolute. The reason |
46 | The filenames you pass to these routines I<must> be absolute. The reason |
42 | is that at the time the request is being executed, the current working |
47 | is that at the time the request is being executed, the current working |
43 | directory could have changed. Alternatively, you can make sure that you |
48 | directory could have changed. Alternatively, you can make sure that you |
44 | never change the current workign directory. |
49 | never change the current working directory. |
45 | |
50 | |
46 | =over 4 |
51 | =over 4 |
47 | |
52 | |
48 | =cut |
53 | =cut |
49 | |
54 | |
50 | package Linux::AIO; |
55 | package Linux::AIO; |
51 | |
56 | |
52 | use base 'Exporter'; |
57 | use base 'Exporter'; |
53 | |
58 | |
54 | BEGIN { |
59 | BEGIN { |
55 | $VERSION = 1.71; |
60 | $VERSION = 1.8; |
56 | |
61 | |
57 | @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat aio_unlink |
62 | @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat aio_unlink |
58 | aio_fsync aio_fdatasync aio_readahead); |
63 | aio_fsync aio_fdatasync aio_readahead); |
59 | @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel nreqs); |
64 | @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel nreqs); |
60 | |
65 | |
… | |
… | |
128 | |
133 | |
129 | Asynchronously open or create a file and call the callback with the |
134 | Asynchronously open or create a file and call the callback with the |
130 | filedescriptor (NOT a perl filehandle, sorry for that, but watch out, this |
135 | filedescriptor (NOT a perl filehandle, sorry for that, but watch out, this |
131 | might change in the future). |
136 | might change in the future). |
132 | |
137 | |
|
|
138 | The pathname passed to C<aio_open> must be absolute. See API NOTES, above, |
|
|
139 | for an explanation. |
|
|
140 | |
133 | The C<$mode> argument is a bitmask. See the C<Fcntl> module for a |
141 | The C<$mode> argument is a bitmask. See the C<Fcntl> module for a |
134 | list. They are the same as used in C<sysopen>. |
142 | list. They are the same as used in C<sysopen>. |
135 | |
143 | |
136 | Example: |
144 | Example: |
137 | |
145 | |
138 | aio_open "/etc/passwd", O_RDONLY, 0, sub { |
146 | aio_open "/etc/passwd", O_RDONLY, 0, sub { |
139 | if ($_[0] >= 0) { |
147 | if ($_[0] >= 0) { |
140 | open my $fh, "<&$_[0]"; # create a copy for perl |
148 | open my $fh, "<&=$_[0]"; |
141 | aio_close $_[0], sub { }; # close the aio handle |
|
|
142 | print "open successful, fh is $fh\n"; |
149 | print "open successful, fh is $fh\n"; |
143 | ... |
150 | ... |
144 | } else { |
151 | } else { |
145 | die "open failed: $!\n"; |
152 | die "open failed: $!\n"; |
146 | } |
153 | } |
… | |
… | |
237 | |
244 | |
238 | - aio_open gives a fd, but all other functions expect a perl filehandle. |
245 | - aio_open gives a fd, but all other functions expect a perl filehandle. |
239 | |
246 | |
240 | =head1 SEE ALSO |
247 | =head1 SEE ALSO |
241 | |
248 | |
242 | L<Coro>. |
249 | L<Coro>, L<IO::AIO>. |
243 | |
250 | |
244 | =head1 AUTHOR |
251 | =head1 AUTHOR |
245 | |
252 | |
246 | Marc Lehmann <schmorp@schmorp.de> |
253 | Marc Lehmann <schmorp@schmorp.de> |
247 | http://home.schmorp.de/ |
254 | http://home.schmorp.de/ |