… | |
… | |
189 | use strict 'vars'; |
189 | use strict 'vars'; |
190 | |
190 | |
191 | use base 'Exporter'; |
191 | use base 'Exporter'; |
192 | |
192 | |
193 | BEGIN { |
193 | BEGIN { |
194 | our $VERSION = '2.41'; |
194 | our $VERSION = '2.5'; |
195 | |
195 | |
196 | our @AIO_REQ = qw(aio_sendfile aio_read aio_write aio_open aio_close aio_stat |
196 | our @AIO_REQ = qw(aio_sendfile aio_read aio_write aio_open aio_close aio_stat |
197 | aio_lstat aio_unlink aio_rmdir aio_readdir aio_scandir aio_symlink |
197 | aio_lstat aio_unlink aio_rmdir aio_readdir aio_scandir aio_symlink |
198 | aio_readlink aio_fsync aio_fdatasync aio_readahead aio_rename aio_link |
198 | aio_readlink aio_fsync aio_fdatasync aio_readahead aio_rename aio_link |
199 | aio_move aio_copy aio_group aio_nop aio_mknod aio_load aio_rmtree aio_mkdir |
199 | aio_move aio_copy aio_group aio_nop aio_mknod aio_load aio_rmtree aio_mkdir |
… | |
… | |
311 | |
311 | |
312 | |
312 | |
313 | =item aio_close $fh, $callback->($status) |
313 | =item aio_close $fh, $callback->($status) |
314 | |
314 | |
315 | Asynchronously close a file and call the callback with the result |
315 | Asynchronously close a file and call the callback with the result |
316 | code. I<WARNING:> although accepted, you should not pass in a perl |
316 | code. |
317 | filehandle here, as perl will likely close the file descriptor another |
|
|
318 | time when the filehandle is destroyed. Normally, you can safely call perls |
|
|
319 | C<close> or just let filehandles go out of scope. |
|
|
320 | |
317 | |
321 | This is supposed to be a bug in the API, so that might change. It's |
318 | Unlike the other functions operating on files, this function uses the |
322 | therefore best to avoid this function. |
319 | PerlIO layer to close the filehandle. The reason is that the PerlIO API |
|
|
320 | insists on closing the underlying fd itself, no matter what, and doesn't |
|
|
321 | allow modifications to the fd. Unfortunately, it is not clear that you can |
|
|
322 | call PerlIO from different threads (actually, its quite clear that this |
|
|
323 | won't work in some cases), so while it likely works perfectly with simple |
|
|
324 | file handles (such as the ones created by C<aio_open>) it might fail in |
|
|
325 | interesting ways for others. |
|
|
326 | |
|
|
327 | Having said that, aio_close tries to clean up the filehandle as much as |
|
|
328 | possible before handing it to an io thread, and generally does work. |
323 | |
329 | |
324 | |
330 | |
325 | =item aio_read $fh,$offset,$length, $data,$dataoffset, $callback->($retval) |
331 | =item aio_read $fh,$offset,$length, $data,$dataoffset, $callback->($retval) |
326 | |
332 | |
327 | =item aio_write $fh,$offset,$length, $data,$dataoffset, $callback->($retval) |
333 | =item aio_write $fh,$offset,$length, $data,$dataoffset, $callback->($retval) |
… | |
… | |
1248 | |
1254 | |
1249 | =back |
1255 | =back |
1250 | |
1256 | |
1251 | =cut |
1257 | =cut |
1252 | |
1258 | |
1253 | # support function to convert a fd into a perl filehandle |
|
|
1254 | sub _fd2fh { |
|
|
1255 | return undef if $_[0] < 0; |
|
|
1256 | |
|
|
1257 | # try to generate nice filehandles |
|
|
1258 | my $sym = "IO::AIO::fd#$_[0]"; |
|
|
1259 | local *$sym; |
|
|
1260 | |
|
|
1261 | open *$sym, "+<&=$_[0]" # usually works under any unix |
|
|
1262 | or open *$sym, "<&=$_[0]" # cygwin needs this |
|
|
1263 | or open *$sym, ">&=$_[0]" # or this |
|
|
1264 | or return undef; |
|
|
1265 | |
|
|
1266 | *$sym |
|
|
1267 | } |
|
|
1268 | |
|
|
1269 | min_parallel 8; |
1259 | min_parallel 8; |
1270 | |
1260 | |
1271 | END { flush } |
1261 | END { flush } |
1272 | |
1262 | |
1273 | 1; |
1263 | 1; |