… | |
… | |
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, |
… | |
… | |
36 | usually delivers "false") as it's sole argument when the given syscall has |
41 | usually delivers "false") as it's sole argument when the given syscall has |
37 | been executed asynchronously. |
42 | been executed asynchronously. |
38 | |
43 | |
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 | |
|
|
46 | The filenames you pass to these routines I<must> be absolute. The reason |
|
|
47 | is that at the time the request is being executed, the current working |
|
|
48 | directory could have changed. Alternatively, you can make sure that you |
|
|
49 | never change the current working directory. |
|
|
50 | |
41 | =over 4 |
51 | =over 4 |
42 | |
52 | |
43 | =cut |
53 | =cut |
44 | |
54 | |
45 | package Linux::AIO; |
55 | package Linux::AIO; |
46 | |
56 | |
47 | use base 'Exporter'; |
57 | use base 'Exporter'; |
48 | |
58 | |
49 | BEGIN { |
59 | BEGIN { |
50 | $VERSION = 1.7; |
60 | $VERSION = 1.9; |
51 | |
61 | |
52 | @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 |
53 | aio_fsync aio_fdatasync aio_readahead); |
63 | aio_fsync aio_fdatasync aio_readahead); |
54 | @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); |
55 | |
65 | |
… | |
… | |
114 | |
124 | |
115 | Returns the number of requests currently outstanding. |
125 | Returns the number of requests currently outstanding. |
116 | |
126 | |
117 | Example: wait till there are no outstanding requests anymore: |
127 | Example: wait till there are no outstanding requests anymore: |
118 | |
128 | |
119 | Linux::AIO::poll_wait while Linux::AIO::nreqs; |
129 | Linux::AIO::poll_wait, Linux::AIO::poll_cb |
|
|
130 | while Linux::AIO::nreqs; |
120 | |
131 | |
121 | =item aio_open $pathname, $flags, $mode, $callback |
132 | =item aio_open $pathname, $flags, $mode, $callback |
122 | |
133 | |
123 | 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 |
124 | 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 |
125 | might change in the future). |
136 | might change in the future). |
126 | |
137 | |
|
|
138 | The pathname passed to C<aio_open> must be absolute. See API NOTES, above, |
|
|
139 | for an explanation. |
|
|
140 | |
127 | 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 |
128 | list. They are the same as used in C<sysopen>. |
142 | list. They are the same as used in C<sysopen>. |
129 | |
143 | |
130 | Example: |
144 | Example: |
131 | |
145 | |
132 | aio_open "/etc/passwd", O_RDONLY, 0, sub { |
146 | aio_open "/etc/passwd", O_RDONLY, 0, sub { |
133 | if ($_[0] >= 0) { |
147 | if ($_[0] >= 0) { |
134 | open my $fh, "<&$_[0]"; # create a copy for perl |
148 | open my $fh, "<&=$_[0]"; |
135 | aio_close $_[0], sub { }; # close the aio handle |
|
|
136 | print "open successful, fh is $fh\n"; |
149 | print "open successful, fh is $fh\n"; |
137 | ... |
150 | ... |
138 | } else { |
151 | } else { |
139 | die "open failed: $!\n"; |
152 | die "open failed: $!\n"; |
140 | } |
153 | } |
… | |
… | |
181 | |
194 | |
182 | Works like perl's C<stat> or C<lstat> in void context. The callback will |
195 | Works like perl's C<stat> or C<lstat> in void context. The callback will |
183 | be called after the stat and the results will be available using C<stat _> |
196 | be called after the stat and the results will be available using C<stat _> |
184 | or C<-s _> etc... |
197 | or C<-s _> etc... |
185 | |
198 | |
|
|
199 | The pathname passed to C<aio_stat> must be absolute. See API NOTES, above, |
|
|
200 | for an explanation. |
|
|
201 | |
186 | Currently, the stats are always 64-bit-stats, i.e. instead of returning an |
202 | Currently, the stats are always 64-bit-stats, i.e. instead of returning an |
187 | error when stat'ing a large file, the results will be silently truncated |
203 | error when stat'ing a large file, the results will be silently truncated |
188 | unless perl itself is compiled with large file support. |
204 | unless perl itself is compiled with large file support. |
189 | |
205 | |
190 | Example: Print the length of F</etc/passwd>: |
206 | Example: Print the length of F</etc/passwd>: |
… | |
… | |
228 | |
244 | |
229 | - 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. |
230 | |
246 | |
231 | =head1 SEE ALSO |
247 | =head1 SEE ALSO |
232 | |
248 | |
233 | L<Coro>. |
249 | L<Coro>, L<IO::AIO>. |
234 | |
250 | |
235 | =head1 AUTHOR |
251 | =head1 AUTHOR |
236 | |
252 | |
237 | Marc Lehmann <schmorp@schmorp.de> |
253 | Marc Lehmann <schmorp@schmorp.de> |
238 | http://home.schmorp.de/ |
254 | http://home.schmorp.de/ |