ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/AIO.pm
(Generate patch)

Comparing IO-AIO/AIO.pm (file contents):
Revision 1.24 by root, Sun Jul 31 18:45:48 2005 UTC vs.
Revision 1.27 by root, Tue Aug 16 22:22:18 2005 UTC

66 66
67BEGIN { 67BEGIN {
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
157Asynchronously reads the specified byte range into the page cache, using
158the C<readahead> syscall. If that syscall doesn't exist (likely if your OS
159isn't Linux) the status will be C<-1> and C<$!> is set to C<ENOSYS>.
160
161C<aio_readahead> populates the page cache with data from a file so that 157C<aio_readahead> populates the page cache with data from a file so that
162subsequent reads from that file will not block on disk I/O. The C<$offset> 158subsequent reads from that file will not block on disk I/O. The C<$offset>
163argument specifies the starting point from which data is to be read and 159argument specifies the starting point from which data is to be read and
164C<$length> specifies the number of bytes to be read. I/O is performed in 160C<$length> specifies the number of bytes to be read. I/O is performed in
165whole pages, so that offset is effectively rounded down to a page boundary 161whole pages, so that offset is effectively rounded down to a page boundary
166and bytes are read up to the next page boundary greater than or equal to 162and 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
168file. The current file offset of the file is left unchanged. 164file. The current file offset of the file is left unchanged.
169 165
166If that syscall doesn't exist (likely if your OS isn't Linux) it will be
167emulated 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
174Works like perl's C<stat> or C<lstat> in void context. The callback will 173Works 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
194Asynchronously unlink (delete) a file and call the callback with the 193Asynchronously unlink (delete) a file and call the callback with the
195result code. 194result code.
196 195
196=item aio_rmdir $pathname, $callback
197
198Asynchronously rmdir (delete) a directory and call the callback with the
199result code.
200
197=item aio_fsync $fh, $callback 201=item aio_fsync $fh, $callback
198 202
199Asynchronously call fsync on the given filehandle and call the callback 203Asynchronously call fsync on the given filehandle and call the callback
200with the fsync result code. 204with the fsync result code.
201 205
202=item aio_fdatasync $fh, $callback 206=item aio_fdatasync $fh, $callback
203 207
204Asynchronously call fdatasync on the given filehandle and call the 208Asynchronously call fdatasync on the given filehandle and call the
205callback with the fdatasync result code. Might set C<$!> to C<ENOSYS> if 209callback with the fdatasync result code.
206C<fdatasync> is not available. 210
211If this call isn't available because your OS lacks it or it couldn't be
212detected, 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
3331; 3421;
334 343
344=head2 FORK BEHAVIOUR
345
346IO::AIO handles all outstanding AIO requests before the fork, destroys all
347AIO threads, and recreates them in both the parent and the child after the
348fork.
349
350
335=head1 SEE ALSO 351=head1 SEE ALSO
336 352
337L<Coro>, L<Linux::AIO>. 353L<Coro>, L<Linux::AIO>.
338 354
339=head1 AUTHOR 355=head1 AUTHOR

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines