--- IO-AIO/AIO.pm 2005/07/10 22:19:54 1.7 +++ IO-AIO/AIO.pm 2005/07/11 02:53:59 1.14 @@ -14,7 +14,7 @@ aio_unlink "/tmp/file", sub { }; aio_read $fh, 30000, 1024, $buffer, 0, sub { - $_[0] >= 0 or die "read error: $!"; + $_[0] > 0 or die "read error: $!"; }; # Event @@ -30,6 +30,11 @@ Tk::Event::IO->fileevent (IO::AIO::poll_fileno, "", readable => \&IO::AIO::poll_cb); + # Danga::Socket + Danga::Socket->AddOtherFds (IO::AIO::poll_fileno => + \&IO::AIO::poll_cb); + + =head1 DESCRIPTION This module implements asynchronous I/O using whatever means your @@ -56,7 +61,7 @@ use Fcntl (); BEGIN { - $VERSION = 0.2; + $VERSION = 0.3; @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat aio_unlink aio_fsync aio_fdatasync aio_readahead); @@ -72,11 +77,11 @@ All the C calls are more or less thin wrappers around the syscall with the same name (sans C). The arguments are similar or identical, -and they all accept an additional C<$callback> argument which must be -a code reference. This code reference will get called with the syscall -return code (e.g. most syscalls return C<-1> on error, unlike perl, which -usually delivers "false") as it's sole argument when the given syscall has -been executed asynchronously. +and they all accept an additional (and optional) C<$callback> argument +which must be a code reference. This code reference will get called with +the syscall return code (e.g. most syscalls return C<-1> on error, unlike +perl, which usually delivers "false") as it's sole argument when the given +syscall has been executed asynchronously. All functions that expect a filehandle will also accept a file descriptor. @@ -130,8 +135,8 @@ offset C<0> within the scalar: aio_read $fh, 7, 15, $buffer, 0, sub { - $_[0] >= 0 or die "read error: $!"; - print "read <$buffer>\n"; + $_[0] > 0 or die "read error: $!"; + print "read $_[0] bytes: <$buffer>\n"; }; =item aio_readahead $fh,$offset,$length, $callback @@ -230,6 +235,24 @@ IO::AIO::poll_wait, IO::AIO::poll_cb while IO::AIO::nreqs; +=item IO::AIO::flush + +Wait till all outstanding AIO requests have been handled. + +Strictly equivalent to: + + IO::AIO::poll_wait, IO::AIO::poll_cb + while IO::AIO::nreqs; + +=item IO::AIO::poll + +Waits until some requests have been handled. + +Strictly equivalent to: + + IO::AIO::poll_wait, IO::AIO::poll_cb + if IO::AIO::nreqs; + =item IO::AIO::min_parallel $nthreads Set the minimum number of AIO threads to C<$nthreads>. The default is