1 |
root |
1.1 |
=head1 NAME |
2 |
|
|
|
3 |
|
|
Linux::AIO - linux-specific aio implemented using clone |
4 |
|
|
|
5 |
|
|
=head1 SYNOPSIS |
6 |
|
|
|
7 |
|
|
use Linux::AIO; |
8 |
|
|
|
9 |
|
|
=head1 DESCRIPTION |
10 |
|
|
|
11 |
root |
1.3 |
This module implements asynchroneous i/o using the means available to |
12 |
|
|
linux - clone. It does not hook into the POSIX aio_* functions because |
13 |
|
|
linux does not yet support these in the kernel. Instead, a number of |
14 |
|
|
threads are started that execute your read/writes and signal their |
15 |
|
|
completion. |
16 |
|
|
|
17 |
root |
1.1 |
=over 4 |
18 |
|
|
|
19 |
|
|
=cut |
20 |
|
|
|
21 |
|
|
package Linux::AIO; |
22 |
|
|
|
23 |
root |
1.2 |
use base 'Exporter'; |
24 |
|
|
|
25 |
root |
1.1 |
BEGIN { |
26 |
root |
1.13 |
$VERSION = 0.2; |
27 |
root |
1.1 |
|
28 |
root |
1.10 |
@EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat); |
29 |
root |
1.2 |
@EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel nreqs); |
30 |
|
|
|
31 |
root |
1.1 |
require XSLoader; |
32 |
|
|
XSLoader::load Linux::AIO, $VERSION; |
33 |
|
|
} |
34 |
|
|
|
35 |
|
|
=item Linux::AIO::min_parallel($nthreads) |
36 |
|
|
|
37 |
root |
1.3 |
Set the minimum number of AIO threads to $nthreads. You I<have> to call |
38 |
|
|
this function with a positive number at leats once, otherwise no threads |
39 |
|
|
will be started and you aio-operations will seem to hang. |
40 |
root |
1.1 |
|
41 |
root |
1.2 |
=item $fileno = Linux::AIO::poll_fileno |
42 |
|
|
|
43 |
|
|
Return the request result pipe filehandle. This filehandle must be polled |
44 |
|
|
for reading. If the pipe becomes readable you have to call C<poll_cb>. |
45 |
|
|
|
46 |
|
|
=item Linux::AIO::poll_cb |
47 |
|
|
|
48 |
|
|
Process all outstanding events on the result pipe. You have to call this |
49 |
|
|
regularly. Returns the number of events processed. |
50 |
|
|
|
51 |
root |
1.3 |
You 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 |
|
|
|
58 |
root |
1.2 |
=item Linux::AIO::nreqs |
59 |
|
|
|
60 |
|
|
Returns the number of requests currently outstanding. |
61 |
root |
1.4 |
|
62 |
root |
1.10 |
=item aio_open($pathname, $flags, $mode, $callback) |
63 |
|
|
|
64 |
|
|
Asynchronously open or create a file and call the callback with the |
65 |
|
|
filedescriptor. |
66 |
|
|
|
67 |
|
|
=item aio_close($fh, $callback) |
68 |
|
|
|
69 |
|
|
Asynchronously close a file and call the callback with the result code. |
70 |
|
|
|
71 |
root |
1.4 |
=item aio_read($fh,$offset,$length, $data,$dataoffset,$callback) |
72 |
root |
1.9 |
|
73 |
|
|
=item aio_write($fh,$offset,$length, $data,$dataoffset,$callback) |
74 |
root |
1.4 |
|
75 |
|
|
Reads or writes C<length> bytes from the specified C<fh> and C<offset> |
76 |
|
|
into the scalar given by C<data> and offset C<dataoffset> and calls the |
77 |
|
|
callback without the actual number of bytes read (or undef on error). |
78 |
|
|
|
79 |
root |
1.10 |
=item aio_stat($fh_or_path,$callback) |
80 |
root |
1.4 |
|
81 |
root |
1.10 |
=item aio_lstat($fh,$callback) |
82 |
root |
1.5 |
|
83 |
root |
1.10 |
Works like perl's C<stat> or C<lstat> in void context, i.e. the callback |
84 |
|
|
will be called after the stat and the results will be available using |
85 |
|
|
C<stat _> or C<-s _> etc... |
86 |
root |
1.5 |
|
87 |
root |
1.10 |
Currently, the stats are always 64-bit-stats, i.e. instead of returning an |
88 |
|
|
error when stat'ing a large file, the results will be silently truncated |
89 |
|
|
unless perl itself is compiled with large file support. |
90 |
root |
1.2 |
|
91 |
root |
1.1 |
=cut |
92 |
root |
1.2 |
|
93 |
|
|
END { |
94 |
|
|
max_parallel 0; |
95 |
|
|
} |
96 |
root |
1.1 |
|
97 |
|
|
1; |
98 |
|
|
|
99 |
|
|
=back |
100 |
|
|
|
101 |
|
|
=head1 BUGS |
102 |
|
|
|
103 |
|
|
This module has not yet been extensively tested. Watch out! |
104 |
|
|
|
105 |
root |
1.11 |
- perl-threads/fork interaction poorly tested. |
106 |
|
|
- aio_open gives a fd, but all other functions expect a filehandle. |
107 |
root |
1.6 |
|
108 |
root |
1.1 |
=head1 SEE ALSO |
109 |
|
|
|
110 |
|
|
L<Coro>. |
111 |
|
|
|
112 |
|
|
=head1 AUTHOR |
113 |
|
|
|
114 |
|
|
Marc Lehmann <pcg@goof.com> |
115 |
|
|
http://www.goof.com/pcg/marc/ |
116 |
|
|
|
117 |
|
|
=cut |
118 |
|
|
|