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

Comparing Linux-AIO/AIO.pm (file contents):
Revision 1.30 by root, Sat Jul 9 23:30:00 2005 UTC vs.
Revision 1.37 by root, Wed Feb 1 23:47:26 2006 UTC

4 4
5=head1 SYNOPSIS 5=head1 SYNOPSIS
6 6
7 use Linux::AIO; 7 use Linux::AIO;
8 8
9 # This module has been mostly superseded by IO::AIO.
10
9=head1 DESCRIPTION 11=head1 DESCRIPTION
12
13I<This module has been mostly superseded by IO::AIO, which is API
14compatible.>
10 15
11This module implements asynchronous I/O using the means available to Linux 16This module implements asynchronous I/O using the means available to Linux
12- clone. It does not hook into the POSIX aio_* functions because Linux 17- clone. It does not hook into the POSIX aio_* functions because Linux
13does not yet support these in the kernel (even as of 2.6.12, only O_DIRECT 18does not yet support these in the kernel (even as of 2.6.12, only O_DIRECT
14files are supported) and even if, it would only allow aio_read and write, 19files are supported) and even if, it would only allow aio_read and write,
36usually delivers "false") as it's sole argument when the given syscall has 41usually delivers "false") as it's sole argument when the given syscall has
37been executed asynchronously. 42been executed asynchronously.
38 43
39All functions that expect a filehandle will also accept a file descriptor. 44All functions that expect a filehandle will also accept a file descriptor.
40 45
46The filenames you pass to these routines I<must> be absolute. The reason
47is that at the time the request is being executed, the current working
48directory could have changed. Alternatively, you can make sure that you
49never change the current working directory.
50
41=over 4 51=over 4
42 52
43=cut 53=cut
44 54
45package Linux::AIO; 55package Linux::AIO;
46 56
47use base 'Exporter'; 57use base 'Exporter';
48 58
49BEGIN { 59BEGIN {
50 $VERSION = 1.7; 60 $VERSION = 1.9;
51 61
52 @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat aio_unlink 62 @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat aio_unlink
53 aio_fsync aio_fdatasync aio_readahead); 63 aio_fsync aio_fdatasync aio_readahead);
54 @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel nreqs); 64 @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel nreqs);
55 65
114 124
115Returns the number of requests currently outstanding. 125Returns the number of requests currently outstanding.
116 126
117Example: wait till there are no outstanding requests anymore: 127Example: wait till there are no outstanding requests anymore:
118 128
119 Linux::AIO::poll_wait while Linux::AIO::nreqs; 129 Linux::AIO::poll_wait, Linux::AIO::poll_cb
130 while Linux::AIO::nreqs;
120 131
121=item aio_open $pathname, $flags, $mode, $callback 132=item aio_open $pathname, $flags, $mode, $callback
122 133
123Asynchronously open or create a file and call the callback with the 134Asynchronously open or create a file and call the callback with the
124filedescriptor (NOT a perl filehandle, sorry for that, but watch out, this 135filedescriptor (NOT a perl filehandle, sorry for that, but watch out, this
125might change in the future). 136might change in the future).
126 137
138The pathname passed to C<aio_open> must be absolute. See API NOTES, above,
139for an explanation.
140
127The C<$mode> argument is a bitmask. See the C<Fcntl> module for a 141The C<$mode> argument is a bitmask. See the C<Fcntl> module for a
128list. They are the same as used in C<sysopen>. 142list. They are the same as used in C<sysopen>.
129 143
130Example: 144Example:
131 145
132 aio_open "/etc/passwd", O_RDONLY, 0, sub { 146 aio_open "/etc/passwd", O_RDONLY, 0, sub {
133 if ($_[0] >= 0) { 147 if ($_[0] >= 0) {
134 open my $fh, "<&$_[0]"; # create a copy for perl 148 open my $fh, "<&=$_[0]";
135 aio_close $_[0], sub { }; # close the aio handle
136 print "open successful, fh is $fh\n"; 149 print "open successful, fh is $fh\n";
137 ... 150 ...
138 } else { 151 } else {
139 die "open failed: $!\n"; 152 die "open failed: $!\n";
140 } 153 }
181 194
182Works like perl's C<stat> or C<lstat> in void context. The callback will 195Works like perl's C<stat> or C<lstat> in void context. The callback will
183be called after the stat and the results will be available using C<stat _> 196be called after the stat and the results will be available using C<stat _>
184or C<-s _> etc... 197or C<-s _> etc...
185 198
199The pathname passed to C<aio_stat> must be absolute. See API NOTES, above,
200for an explanation.
201
186Currently, the stats are always 64-bit-stats, i.e. instead of returning an 202Currently, the stats are always 64-bit-stats, i.e. instead of returning an
187error when stat'ing a large file, the results will be silently truncated 203error when stat'ing a large file, the results will be silently truncated
188unless perl itself is compiled with large file support. 204unless perl itself is compiled with large file support.
189 205
190Example: Print the length of F</etc/passwd>: 206Example: Print the length of F</etc/passwd>:
228 244
229 - aio_open gives a fd, but all other functions expect a perl filehandle. 245 - aio_open gives a fd, but all other functions expect a perl filehandle.
230 246
231=head1 SEE ALSO 247=head1 SEE ALSO
232 248
233L<Coro>. 249L<Coro>, L<IO::AIO>.
234 250
235=head1 AUTHOR 251=head1 AUTHOR
236 252
237 Marc Lehmann <schmorp@schmorp.de> 253 Marc Lehmann <schmorp@schmorp.de>
238 http://home.schmorp.de/ 254 http://home.schmorp.de/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines