… | |
… | |
14 | aio_unlink "/tmp/file", sub { }; |
14 | aio_unlink "/tmp/file", sub { }; |
15 | |
15 | |
16 | aio_read $fh, 30000, 1024, $buffer, 0, sub { |
16 | aio_read $fh, 30000, 1024, $buffer, 0, sub { |
17 | $_[0] > 0 or die "read error: $!"; |
17 | $_[0] > 0 or die "read error: $!"; |
18 | }; |
18 | }; |
|
|
19 | |
|
|
20 | # AnyEvent |
|
|
21 | open my $fh, "<&=" . IO::AIO::poll_fileno or die "$!"; |
|
|
22 | my $w = AnyEvent->io (fh => $fh, poll => 'r', cb => sub { IO::AIO::poll_cb }); |
19 | |
23 | |
20 | # Event |
24 | # Event |
21 | Event->io (fd => IO::AIO::poll_fileno, |
25 | Event->io (fd => IO::AIO::poll_fileno, |
22 | poll => 'r', |
26 | poll => 'r', |
23 | cb => \&IO::AIO::poll_cb); |
27 | cb => \&IO::AIO::poll_cb); |
… | |
… | |
63 | use base 'Exporter'; |
67 | use base 'Exporter'; |
64 | |
68 | |
65 | use Fcntl (); |
69 | use Fcntl (); |
66 | |
70 | |
67 | BEGIN { |
71 | BEGIN { |
68 | $VERSION = 1.6; |
72 | $VERSION = '1.72'; |
69 | |
73 | |
70 | @EXPORT = qw(aio_sendfile aio_read aio_write aio_open aio_close aio_stat |
74 | @EXPORT = qw(aio_sendfile aio_read aio_write aio_open aio_close aio_stat |
71 | aio_lstat aio_unlink aio_rmdir aio_readdir aio_scandir aio_symlink |
75 | aio_lstat aio_unlink aio_rmdir aio_readdir aio_scandir aio_symlink |
72 | aio_fsync aio_fdatasync aio_readahead); |
76 | aio_fsync aio_fdatasync aio_readahead); |
73 | @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel |
77 | @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel |
… | |
… | |
233 | =item aio_rmdir $pathname, $callback->($status) |
237 | =item aio_rmdir $pathname, $callback->($status) |
234 | |
238 | |
235 | Asynchronously rmdir (delete) a directory and call the callback with the |
239 | Asynchronously rmdir (delete) a directory and call the callback with the |
236 | result code. |
240 | result code. |
237 | |
241 | |
238 | =item aio_readdir $pathname $callback->($entries) |
242 | =item aio_readdir $pathname, $callback->($entries) |
239 | |
243 | |
240 | Unlike the POSIX call of the same name, C<aio_readdir> reads an entire |
244 | Unlike the POSIX call of the same name, C<aio_readdir> reads an entire |
241 | directory (i.e. opendir + readdir + closedir). The entries will not be |
245 | directory (i.e. opendir + readdir + closedir). The entries will not be |
242 | sorted, and will B<NOT> include the C<.> and C<..> entries. |
246 | sorted, and will B<NOT> include the C<.> and C<..> entries. |
243 | |
247 | |
… | |
… | |
278 | |
282 | |
279 | Then entires will be sorted into likely directories (everything without a |
283 | Then entires will be sorted into likely directories (everything without a |
280 | non-initial dot) and likely non-directories (everything else). Then every |
284 | non-initial dot) and likely non-directories (everything else). Then every |
281 | entry + C</.> will be C<stat>'ed, likely directories first. This is often |
285 | entry + C</.> will be C<stat>'ed, likely directories first. This is often |
282 | faster because filesystems might detect the type of the entry without |
286 | faster because filesystems might detect the type of the entry without |
283 | reading the inode data (e.g. ext2s filetype feature). If that succeeds, |
287 | reading the inode data (e.g. ext2fs filetype feature). If that succeeds, |
284 | it assumes that the entry is a directory or a symlink to directory (which |
288 | it assumes that the entry is a directory or a symlink to directory (which |
285 | will be checked seperately). |
289 | will be checked seperately). |
286 | |
290 | |
287 | If the known number of directories has been reached, the rest of the |
291 | If the known number of directories has been reached, the rest of the |
288 | entries is assumed to be non-directories. |
292 | entries is assumed to be non-directories. |
… | |
… | |
294 | |
298 | |
295 | $maxreq = 8 if $maxreq <= 0; |
299 | $maxreq = 8 if $maxreq <= 0; |
296 | |
300 | |
297 | # stat once |
301 | # stat once |
298 | aio_stat $path, sub { |
302 | aio_stat $path, sub { |
299 | $cb->() if $_[0]; |
303 | return $cb->() if $_[0]; |
300 | my $hash1 = join ":", (stat _)[0,1,3,7,9]; |
304 | my $hash1 = join ":", (stat _)[0,1,3,7,9]; |
301 | |
305 | |
302 | # read the directory entries |
306 | # read the directory entries |
303 | aio_readdir $path, sub { |
307 | aio_readdir $path, sub { |
304 | my $entries = shift |
308 | my $entries = shift |
… | |
… | |
315 | $ndirs = -1; |
319 | $ndirs = -1; |
316 | } else { |
320 | } else { |
317 | # if nlink == 2, we are finished |
321 | # if nlink == 2, we are finished |
318 | # on non-posix-fs's, we rely on nlink < 2 |
322 | # on non-posix-fs's, we rely on nlink < 2 |
319 | $ndirs = (stat _)[3] - 2 |
323 | $ndirs = (stat _)[3] - 2 |
320 | or $cb->([], $entries); |
324 | or return $cb->([], $entries); |
321 | } |
325 | } |
322 | |
326 | |
323 | # sort into likely dirs and likely nondirs |
327 | # sort into likely dirs and likely nondirs |
324 | # dirs == files without ".", short entries first |
328 | # dirs == files without ".", short entries first |
325 | $entries = [map $_->[0], |
329 | $entries = [map $_->[0], |
… | |
… | |
341 | } |
345 | } |
342 | } elsif (!$nreq) { |
346 | } elsif (!$nreq) { |
343 | # finished |
347 | # finished |
344 | undef $statcb; |
348 | undef $statcb; |
345 | undef $schedcb; |
349 | undef $schedcb; |
346 | $cb->(\@dirs, \@nondirs); |
350 | $cb->(\@dirs, \@nondirs) if $cb; |
347 | undef $cb; |
351 | undef $cb; |
348 | } |
352 | } |
349 | }; |
353 | }; |
350 | $statcb = sub { |
354 | $statcb = sub { |
351 | my ($status, $entry) = @_; |
355 | my ($status, $entry) = @_; |