… | |
… | |
66 | |
66 | |
67 | BEGIN { |
67 | BEGIN { |
68 | $VERSION = 1.1; |
68 | $VERSION = 1.1; |
69 | |
69 | |
70 | @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat aio_unlink |
70 | @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat aio_unlink |
71 | aio_fsync aio_fdatasync aio_readahead); |
71 | aio_rmdir aio_symlink aio_fsync aio_fdatasync aio_readahead); |
72 | @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel max_outstanding nreqs); |
72 | @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel max_outstanding nreqs); |
73 | |
73 | |
74 | require XSLoader; |
74 | require XSLoader; |
75 | XSLoader::load IO::AIO, $VERSION; |
75 | XSLoader::load IO::AIO, $VERSION; |
76 | } |
76 | } |
… | |
… | |
152 | print "read $_[0] bytes: <$buffer>\n"; |
152 | print "read $_[0] bytes: <$buffer>\n"; |
153 | }; |
153 | }; |
154 | |
154 | |
155 | =item aio_readahead $fh,$offset,$length, $callback |
155 | =item aio_readahead $fh,$offset,$length, $callback |
156 | |
156 | |
157 | Asynchronously reads the specified byte range into the page cache, using |
|
|
158 | the C<readahead> syscall. If that syscall doesn't exist (likely if your OS |
|
|
159 | isn't Linux) the status will be C<-1> and C<$!> is set to C<ENOSYS>. |
|
|
160 | |
|
|
161 | C<aio_readahead> populates the page cache with data from a file so that |
157 | C<aio_readahead> populates the page cache with data from a file so that |
162 | subsequent reads from that file will not block on disk I/O. The C<$offset> |
158 | subsequent reads from that file will not block on disk I/O. The C<$offset> |
163 | argument specifies the starting point from which data is to be read and |
159 | argument specifies the starting point from which data is to be read and |
164 | C<$length> specifies the number of bytes to be read. I/O is performed in |
160 | C<$length> specifies the number of bytes to be read. I/O is performed in |
165 | whole pages, so that offset is effectively rounded down to a page boundary |
161 | whole pages, so that offset is effectively rounded down to a page boundary |
166 | and bytes are read up to the next page boundary greater than or equal to |
162 | and bytes are read up to the next page boundary greater than or equal to |
167 | (off-set+length). C<aio_readahead> does not read beyond the end of the |
163 | (off-set+length). C<aio_readahead> does not read beyond the end of the |
168 | file. The current file offset of the file is left unchanged. |
164 | file. The current file offset of the file is left unchanged. |
169 | |
165 | |
|
|
166 | If that syscall doesn't exist (likely if your OS isn't Linux) it will be |
|
|
167 | emulated by simply reading the data, which would have a similar effect. |
|
|
168 | |
170 | =item aio_stat $fh_or_path, $callback |
169 | =item aio_stat $fh_or_path, $callback |
171 | |
170 | |
172 | =item aio_lstat $fh, $callback |
171 | =item aio_lstat $fh, $callback |
173 | |
172 | |
174 | Works like perl's C<stat> or C<lstat> in void context. The callback will |
173 | Works like perl's C<stat> or C<lstat> in void context. The callback will |
… | |
… | |
192 | =item aio_unlink $pathname, $callback |
191 | =item aio_unlink $pathname, $callback |
193 | |
192 | |
194 | Asynchronously unlink (delete) a file and call the callback with the |
193 | Asynchronously unlink (delete) a file and call the callback with the |
195 | result code. |
194 | result code. |
196 | |
195 | |
|
|
196 | =item aio_rmdir $pathname, $callback |
|
|
197 | |
|
|
198 | Asynchronously rmdir (delete) a directory and call the callback with the |
|
|
199 | result code. |
|
|
200 | |
197 | =item aio_fsync $fh, $callback |
201 | =item aio_fsync $fh, $callback |
198 | |
202 | |
199 | Asynchronously call fsync on the given filehandle and call the callback |
203 | Asynchronously call fsync on the given filehandle and call the callback |
200 | with the fsync result code. |
204 | with the fsync result code. |
201 | |
205 | |
202 | =item aio_fdatasync $fh, $callback |
206 | =item aio_fdatasync $fh, $callback |
203 | |
207 | |
204 | Asynchronously call fdatasync on the given filehandle and call the |
208 | Asynchronously call fdatasync on the given filehandle and call the |
205 | callback with the fdatasync result code. Might set C<$!> to C<ENOSYS> if |
209 | callback with the fdatasync result code. |
206 | C<fdatasync> is not available. |
210 | |
|
|
211 | If this call isn't available because your OS lacks it or it couldn't be |
|
|
212 | detected, it will be emulated by calling C<fsync> instead. |
207 | |
213 | |
208 | =back |
214 | =back |
209 | |
215 | |
210 | =head2 SUPPORT FUNCTIONS |
216 | =head2 SUPPORT FUNCTIONS |
211 | |
217 | |
… | |
… | |
316 | return undef if $_[0] < 0; |
322 | return undef if $_[0] < 0; |
317 | |
323 | |
318 | # try to generate nice filehandles |
324 | # try to generate nice filehandles |
319 | my $sym = "IO::AIO::fd#$_[0]"; |
325 | my $sym = "IO::AIO::fd#$_[0]"; |
320 | local *$sym; |
326 | local *$sym; |
321 | open *$sym, "+<&=$_[0]" |
327 | |
|
|
328 | open *$sym, "+<&=$_[0]" # usually works under any unix |
|
|
329 | or open *$sym, "<&=$_[0]" # cygwin needs this |
|
|
330 | or open *$sym, ">&=$_[0]" # or this |
322 | or return undef; |
331 | or return undef; |
323 | |
332 | |
324 | *$sym |
333 | *$sym |
325 | } |
334 | } |
326 | |
335 | |
… | |
… | |
330 | max_parallel 0; |
339 | max_parallel 0; |
331 | } |
340 | } |
332 | |
341 | |
333 | 1; |
342 | 1; |
334 | |
343 | |
|
|
344 | =head2 FORK BEHAVIOUR |
|
|
345 | |
|
|
346 | IO::AIO handles all outstanding AIO requests before the fork, destroys all |
|
|
347 | AIO threads, and recreates them in both the parent and the child after the |
|
|
348 | fork. |
|
|
349 | |
|
|
350 | |
335 | =head1 SEE ALSO |
351 | =head1 SEE ALSO |
336 | |
352 | |
337 | L<Coro>, L<Linux::AIO>. |
353 | L<Coro>, L<Linux::AIO>. |
338 | |
354 | |
339 | =head1 AUTHOR |
355 | =head1 AUTHOR |