… | |
… | |
63 | use base 'Exporter'; |
63 | use base 'Exporter'; |
64 | |
64 | |
65 | use Fcntl (); |
65 | use Fcntl (); |
66 | |
66 | |
67 | BEGIN { |
67 | BEGIN { |
68 | $VERSION = '1.0'; |
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_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 | |
… | |
… | |
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 |
… | |
… | |
200 | with the fsync result code. |
199 | with the fsync result code. |
201 | |
200 | |
202 | =item aio_fdatasync $fh, $callback |
201 | =item aio_fdatasync $fh, $callback |
203 | |
202 | |
204 | Asynchronously call fdatasync on the given filehandle and call the |
203 | Asynchronously call fdatasync on the given filehandle and call the |
205 | callback with the fdatasync result code. Might set C<$!> to C<ENOSYS> if |
204 | callback with the fdatasync result code. |
206 | C<fdatasync> is not available. |
205 | |
|
|
206 | If this call isn't available because your OS lacks it or it couldn't be |
|
|
207 | detected, it will be emulated by calling C<fsync> instead. |
207 | |
208 | |
208 | =back |
209 | =back |
209 | |
210 | |
210 | =head2 SUPPORT FUNCTIONS |
211 | =head2 SUPPORT FUNCTIONS |
211 | |
212 | |
… | |
… | |
316 | return undef if $_[0] < 0; |
317 | return undef if $_[0] < 0; |
317 | |
318 | |
318 | # try to generate nice filehandles |
319 | # try to generate nice filehandles |
319 | my $sym = "IO::AIO::fd#$_[0]"; |
320 | my $sym = "IO::AIO::fd#$_[0]"; |
320 | local *$sym; |
321 | local *$sym; |
321 | open *$sym, "+<&=$_[0]" |
322 | |
|
|
323 | open *$sym, "+<&$_[0]" # usually under any unix |
|
|
324 | or open *$sym, "<&$_[0]" # cygwin needs this |
|
|
325 | or open *$sym, ">&$_[0]" # cygwin needs this |
322 | or return undef; |
326 | or return undef; |
323 | |
327 | |
324 | *$sym |
328 | *$sym |
325 | } |
329 | } |
326 | |
330 | |