--- Coro/Coro/AIO.pm 2005/12/26 18:48:11 1.1 +++ Coro/Coro/AIO.pm 2005/12/26 19:26:52 1.2 @@ -1,13 +1,13 @@ =head1 NAME -Coro::AIO - truely asynchronous file access +Coro::AIO - truly asynchronous file and directrory I/O =head1 SYNOPSIS use Coro::AIO; - # can now use any of: - # aio_sendfile aio_read aio_write aio_open aio_close + # can now use any of + # aio_sendfile aio_read aio_write aio_open aio_close aio_stat aio_lstat # aio_unlink aio_rmdir aio_readdir aio_scandir aio_symlink aio_fsync # aio_fdatasync aio_readahead @@ -21,14 +21,14 @@ =head1 DESCRIPTION This module implements a thin wrapper around L. All of -the functions (except C and C) that expect a callback -are being wrapped by this module. +the functions that expect a callback are being wrapped by this module. The API is exactly the same as that of the corresponding IO::AIO routines, except that you have to specify I arguments I the callback argument. Instead the routines return the values normally passed to the callback. They also all have a prototype of C<@> currently, but that might -change. +change. Everything else, including C<$!> and perls stat cache, are set as +expected after these functions return. You can mix calls to C functions with calls to this module. You also can, but do not need to, call C, as this module @@ -46,6 +46,8 @@ package Coro::AIO; +use strict; + use Coro (); use AnyEvent; use IO::AIO (); @@ -59,6 +61,8 @@ sub wrap($) { my ($sub) = @_; + + no strict 'refs'; push @EXPORT, $sub; @@ -66,11 +70,11 @@ *$sub = sub { my $current = $Coro::current; - my $errno; + my $stat; my @res; $iosub->(@_, sub { - $errno = $!; + $stat = Coro::_aio_get_state; @res = @_; $current->ready; undef $current; @@ -78,14 +82,14 @@ Coro::schedule while $current; - $! = $errno; + Coro::_aio_set_state $stat; wantarray ? @res : $res[0] }; } -wrap $_ for qw(aio_sendfile aio_read aio_write aio_open aio_close - aio_unlink aio_rmdir aio_readdir aio_scandir aio_symlink - aio_fsync aio_fdatasync aio_readahead); +wrap $_ for qw(aio_sendfile aio_read aio_write aio_open aio_close aio_stat + aio_lstat aio_unlink aio_rmdir aio_readdir aio_scandir + aio_symlink aio_fsync aio_fdatasync aio_readahead); =item $fh = aio_open $pathname, $flags, $mode @@ -99,6 +103,10 @@ =item $retval = aio_readahead $fh,$offset,$length +=item $status = aio_stat $fh_or_path + +=item $status = aio_lstat $fh + =item $status = aio_unlink $pathname =item $status = aio_rmdir $pathname @@ -113,6 +121,10 @@ =back +=head1 SEE ALSO + +L and L for non-blocking file operation. + =head1 AUTHOR Marc Lehmann