… | |
… | |
36 | usually delivers "false") as it's sole argument when the given syscall has |
36 | usually delivers "false") as it's sole argument when the given syscall has |
37 | been executed asynchronously. |
37 | been executed asynchronously. |
38 | |
38 | |
39 | All functions that expect a filehandle will also accept a file descriptor. |
39 | All functions that expect a filehandle will also accept a file descriptor. |
40 | |
40 | |
|
|
41 | 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 |
|
|
43 | directory could have changed. Alternatively, you can make sure that you |
|
|
44 | never change the current working directory. |
|
|
45 | |
41 | =over 4 |
46 | =over 4 |
42 | |
47 | |
43 | =cut |
48 | =cut |
44 | |
49 | |
45 | package Linux::AIO; |
50 | package Linux::AIO; |
46 | |
51 | |
47 | use base 'Exporter'; |
52 | use base 'Exporter'; |
48 | |
53 | |
49 | BEGIN { |
54 | BEGIN { |
50 | $VERSION = 1.71; |
55 | $VERSION = 1.72; |
51 | |
56 | |
52 | @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat aio_unlink |
57 | @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat aio_unlink |
53 | aio_fsync aio_fdatasync aio_readahead); |
58 | aio_fsync aio_fdatasync aio_readahead); |
54 | @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel nreqs); |
59 | @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel nreqs); |
55 | |
60 | |
… | |
… | |
114 | |
119 | |
115 | Returns the number of requests currently outstanding. |
120 | Returns the number of requests currently outstanding. |
116 | |
121 | |
117 | Example: wait till there are no outstanding requests anymore: |
122 | Example: wait till there are no outstanding requests anymore: |
118 | |
123 | |
119 | Linux::AIO::poll_wait while Linux::AIO::nreqs; |
124 | Linux::AIO::poll_wait, Linux::AIO::poll_cb |
|
|
125 | while Linux::AIO::nreqs; |
120 | |
126 | |
121 | =item aio_open $pathname, $flags, $mode, $callback |
127 | =item aio_open $pathname, $flags, $mode, $callback |
122 | |
128 | |
123 | Asynchronously open or create a file and call the callback with the |
129 | 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 |
130 | filedescriptor (NOT a perl filehandle, sorry for that, but watch out, this |
125 | might change in the future). |
131 | might change in the future). |
126 | |
132 | |
|
|
133 | The pathname passed to C<aio_open> must be absolute. See API NOTES, above, |
|
|
134 | for an explanation. |
|
|
135 | |
127 | The C<$mode> argument is a bitmask. See the C<Fcntl> module for a |
136 | 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>. |
137 | list. They are the same as used in C<sysopen>. |
129 | |
138 | |
130 | Example: |
139 | Example: |
131 | |
140 | |
132 | aio_open "/etc/passwd", O_RDONLY, 0, sub { |
141 | aio_open "/etc/passwd", O_RDONLY, 0, sub { |
133 | if ($_[0] >= 0) { |
142 | if ($_[0] >= 0) { |
134 | open my $fh, "<&$_[0]"; # create a copy for perl |
143 | open my $fh, "<&=$_[0]"; |
135 | aio_close $_[0], sub { }; # close the aio handle |
|
|
136 | print "open successful, fh is $fh\n"; |
144 | print "open successful, fh is $fh\n"; |
137 | ... |
145 | ... |
138 | } else { |
146 | } else { |
139 | die "open failed: $!\n"; |
147 | die "open failed: $!\n"; |
140 | } |
148 | } |
… | |
… | |
181 | |
189 | |
182 | Works like perl's C<stat> or C<lstat> in void context. The callback will |
190 | 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 _> |
191 | be called after the stat and the results will be available using C<stat _> |
184 | or C<-s _> etc... |
192 | or C<-s _> etc... |
185 | |
193 | |
|
|
194 | The pathname passed to C<aio_stat> must be absolute. See API NOTES, above, |
|
|
195 | for an explanation. |
|
|
196 | |
186 | Currently, the stats are always 64-bit-stats, i.e. instead of returning an |
197 | 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 |
198 | error when stat'ing a large file, the results will be silently truncated |
188 | unless perl itself is compiled with large file support. |
199 | unless perl itself is compiled with large file support. |
189 | |
200 | |
190 | Example: Print the length of F</etc/passwd>: |
201 | Example: Print the length of F</etc/passwd>: |
… | |
… | |
228 | |
239 | |
229 | - aio_open gives a fd, but all other functions expect a perl filehandle. |
240 | - aio_open gives a fd, but all other functions expect a perl filehandle. |
230 | |
241 | |
231 | =head1 SEE ALSO |
242 | =head1 SEE ALSO |
232 | |
243 | |
233 | L<Coro>. |
244 | L<Coro>, L<IO::AIO>. |
234 | |
245 | |
235 | =head1 AUTHOR |
246 | =head1 AUTHOR |
236 | |
247 | |
237 | Marc Lehmann <schmorp@schmorp.de> |
248 | Marc Lehmann <schmorp@schmorp.de> |
238 | http://home.schmorp.de/ |
249 | http://home.schmorp.de/ |