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.2 by root, Tue Aug 14 18:06:37 2001 UTC vs.
Revision 1.10 by root, Mon Apr 1 20:30:08 2002 UTC

6 6
7 use Linux::AIO; 7 use Linux::AIO;
8 8
9=head1 DESCRIPTION 9=head1 DESCRIPTION
10 10
11This module implements asynchroneous i/o using the means available to
12linux - clone. It does not hook into the POSIX aio_* functions because
13linux does not yet support these in the kernel. Instead, a number of
14threads are started that execute your read/writes and signal their
15completion.
16
11=over 4 17=over 4
12 18
13=cut 19=cut
14 20
15package Linux::AIO; 21package Linux::AIO;
16 22
17use base 'Exporter'; 23use base 'Exporter';
18 24
19BEGIN { 25BEGIN {
20 $VERSION = 0.001; 26 $VERSION = 0.011;
21 27
22 @EXPORT = qw(aio_read aio_write); 28 @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat);
23 @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel nreqs); 29 @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel nreqs);
24 30
25 require XSLoader; 31 require XSLoader;
26 XSLoader::load Linux::AIO, $VERSION; 32 XSLoader::load Linux::AIO, $VERSION;
27} 33}
28 34
29=item Linux::AIO::min_parallel($nthreads) 35=item Linux::AIO::min_parallel($nthreads)
30 36
31Set the minimum number of AIO threads to $nthreads. 37Set the minimum number of AIO threads to $nthreads. You I<have> to call
32 38this function with a positive number at leats once, otherwise no threads
33=cut 39will be started and you aio-operations will seem to hang.
34
35=item aio_read($fh,$offset,$length, $data,$dataoffset,$callback)
36aio_write($fh,$offset,$length, $data,$dataoffset,$callback)
37
38Reads or writes C<length> bytes from the specified C<fh> and C<offset>
39into the scalar given by C<data> and offset C<dataoffset> and calls the
40callback without the actual number of bytes read (or undef on error).
41 40
42=item $fileno = Linux::AIO::poll_fileno 41=item $fileno = Linux::AIO::poll_fileno
43 42
44Return the request result pipe filehandle. This filehandle must be polled 43Return the request result pipe filehandle. This filehandle must be polled
45for reading. If the pipe becomes readable you have to call C<poll_cb>. 44for reading. If the pipe becomes readable you have to call C<poll_cb>.
47=item Linux::AIO::poll_cb 46=item Linux::AIO::poll_cb
48 47
49Process all outstanding events on the result pipe. You have to call this 48Process all outstanding events on the result pipe. You have to call this
50regularly. Returns the number of events processed. 49regularly. Returns the number of events processed.
51 50
51You can use Event to multiplex, e.g.:
52
53 Event->io(fd => Linux::AIO::poll_fileno,
54 poll => 'r', async => 1,
55 cb => \&Linux::AIO::poll_cb );
56
57
52=item Linux::AIO::nreqs 58=item Linux::AIO::nreqs
53 59
54Returns the number of requests currently outstanding. 60Returns the number of requests currently outstanding.
61
62=item aio_open($pathname, $flags, $mode, $callback)
63
64Asynchronously open or create a file and call the callback with the
65filedescriptor.
66
67=item aio_close($fh, $callback)
68
69Asynchronously close a file and call the callback with the result code.
70
71=item aio_read($fh,$offset,$length, $data,$dataoffset,$callback)
72
73=item aio_write($fh,$offset,$length, $data,$dataoffset,$callback)
74
75Reads or writes C<length> bytes from the specified C<fh> and C<offset>
76into the scalar given by C<data> and offset C<dataoffset> and calls the
77callback without the actual number of bytes read (or undef on error).
78
79=item aio_stat($fh_or_path,$callback)
80
81=item aio_lstat($fh,$callback)
82
83Works like perl's C<stat> or C<lstat> in void context, i.e. the callback
84will be called after the stat and the results will be available using
85C<stat _> or C<-s _> etc...
86
87Currently, the stats are always 64-bit-stats, i.e. instead of returning an
88error when stat'ing a large file, the results will be silently truncated
89unless perl itself is compiled with large file support.
55 90
56=cut 91=cut
57 92
58END { 93END {
59 max_parallel 0; 94 max_parallel 0;
65 100
66=head1 BUGS 101=head1 BUGS
67 102
68This module has not yet been extensively tested. Watch out! 103This module has not yet been extensively tested. Watch out!
69 104
70This module does not use the aio_* posix functions because a) linux does 105 - aio_stat/lstat are seriously missing here.
71not have aio, b) the existing aio_* functions use pthreads, which are too
72buggy for my usage.
73 106
74=head1 SEE ALSO 107=head1 SEE ALSO
75 108
76L<Coro>. 109L<Coro>.
77 110

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines