ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/AIO.pm
(Generate patch)

Comparing IO-AIO/AIO.pm (file contents):
Revision 1.6 by root, Sun Jul 10 22:19:48 2005 UTC vs.
Revision 1.15 by root, Mon Jul 11 03:09:00 2005 UTC

12 }; 12 };
13 13
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 19
20 # Event 20 # Event
21 Event->io (fd => IO::AIO::poll_fileno, 21 Event->io (fd => IO::AIO::poll_fileno,
22 poll => 'r', async => 1, 22 poll => 'r',
23 cb => \&IO::AIO::poll_cb); 23 cb => \&IO::AIO::poll_cb);
24 24
25 # Glib/Gtk2 25 # Glib/Gtk2
26 add_watch Glib::IO IO::AIO::poll_fileno, 26 add_watch Glib::IO IO::AIO::poll_fileno,
27 \&IO::AIO::poll_cb; 27 sub { IO::AIO::poll_cb, 1 };
28 28
29 # Tk 29 # Tk
30 Tk::Event::IO->fileevent (IO::AIO::poll_fileno, "", 30 Tk::Event::IO->fileevent (IO::AIO::poll_fileno, "",
31 readable => \&IO::AIO::poll_cb); 31 readable => \&IO::AIO::poll_cb);
32
33 # Danga::Socket
34 Danga::Socket->AddOtherFds (IO::AIO::poll_fileno =>
35 \&IO::AIO::poll_cb);
36
32 37
33=head1 DESCRIPTION 38=head1 DESCRIPTION
34 39
35This module implements asynchronous I/O using whatever means your 40This module implements asynchronous I/O using whatever means your
36operating system supports. 41operating system supports.
54use base 'Exporter'; 59use base 'Exporter';
55 60
56use Fcntl (); 61use Fcntl ();
57 62
58BEGIN { 63BEGIN {
59 $VERSION = 0.2; 64 $VERSION = 0.3;
60 65
61 @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat aio_unlink 66 @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat aio_unlink
62 aio_fsync aio_fdatasync aio_readahead); 67 aio_fsync aio_fdatasync aio_readahead);
63 @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel max_outstanding nreqs); 68 @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel max_outstanding nreqs);
64 69
70 75
71=head2 AIO FUNCTIONS 76=head2 AIO FUNCTIONS
72 77
73All the C<aio_*> calls are more or less thin wrappers around the syscall 78All the C<aio_*> calls are more or less thin wrappers around the syscall
74with the same name (sans C<aio_>). The arguments are similar or identical, 79with the same name (sans C<aio_>). The arguments are similar or identical,
75and they all accept an additional C<$callback> argument which must be 80and they all accept an additional (and optional) C<$callback> argument
76a code reference. This code reference will get called with the syscall 81which must be a code reference. This code reference will get called with
77return code (e.g. most syscalls return C<-1> on error, unlike perl, which 82the syscall return code (e.g. most syscalls return C<-1> on error, unlike
78usually delivers "false") as it's sole argument when the given syscall has 83perl, which usually delivers "false") as it's sole argument when the given
79been executed asynchronously. 84syscall has been executed asynchronously.
80 85
81All functions that expect a filehandle will also accept a file descriptor. 86All functions that expect a filehandle will also accept a file descriptor.
82 87
83The filenames you pass to these routines I<must> be absolute. The reason 88The filenames you pass to these routines I<must> be absolute. The reason
84is that at the time the request is being executed, the current working 89is that at the time the request is being executed, the current working
128 133
129Example: Read 15 bytes at offset 7 into scalar C<$buffer>, strating at 134Example: Read 15 bytes at offset 7 into scalar C<$buffer>, strating at
130offset C<0> within the scalar: 135offset C<0> within the scalar:
131 136
132 aio_read $fh, 7, 15, $buffer, 0, sub { 137 aio_read $fh, 7, 15, $buffer, 0, sub {
133 $_[0] >= 0 or die "read error: $!"; 138 $_[0] > 0 or die "read error: $!";
134 print "read <$buffer>\n"; 139 print "read $_[0] bytes: <$buffer>\n";
135 }; 140 };
136 141
137=item aio_readahead $fh,$offset,$length, $callback 142=item aio_readahead $fh,$offset,$length, $callback
138 143
139Asynchronously reads the specified byte range into the page cache, using 144Asynchronously reads the specified byte range into the page cache, using
228Example: wait till there are no outstanding requests anymore: 233Example: wait till there are no outstanding requests anymore:
229 234
230 IO::AIO::poll_wait, IO::AIO::poll_cb 235 IO::AIO::poll_wait, IO::AIO::poll_cb
231 while IO::AIO::nreqs; 236 while IO::AIO::nreqs;
232 237
238=item IO::AIO::flush
239
240Wait till all outstanding AIO requests have been handled.
241
242Strictly equivalent to:
243
244 IO::AIO::poll_wait, IO::AIO::poll_cb
245 while IO::AIO::nreqs;
246
247=item IO::AIO::poll
248
249Waits until some requests have been handled.
250
251Strictly equivalent to:
252
253 IO::AIO::poll_wait, IO::AIO::poll_cb
254 if IO::AIO::nreqs;
255
233=item IO::AIO::min_parallel $nthreads 256=item IO::AIO::min_parallel $nthreads
234 257
235Set the minimum number of AIO threads to C<$nthreads>. The default is 258Set the minimum number of AIO threads to C<$nthreads>. The default is
236C<1>, which means a single asynchronous operation can be done at one time 259C<1>, which means a single asynchronous operation can be done at one time
237(the number of outstanding operations, however, is unlimited). 260(the number of outstanding operations, however, is unlimited).

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines