… | |
… | |
21 | package Linux::AIO; |
21 | package Linux::AIO; |
22 | |
22 | |
23 | use base 'Exporter'; |
23 | use base 'Exporter'; |
24 | |
24 | |
25 | BEGIN { |
25 | BEGIN { |
26 | $VERSION = 0.001; |
26 | $VERSION = 0.2; |
27 | |
27 | |
28 | @EXPORT = qw(aio_read aio_write); |
28 | @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat); |
29 | @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); |
30 | |
30 | |
31 | require XSLoader; |
31 | require XSLoader; |
32 | XSLoader::load Linux::AIO, $VERSION; |
32 | XSLoader::load Linux::AIO, $VERSION; |
33 | } |
33 | } |
… | |
… | |
35 | =item Linux::AIO::min_parallel($nthreads) |
35 | =item Linux::AIO::min_parallel($nthreads) |
36 | |
36 | |
37 | Set the minimum number of AIO threads to $nthreads. You I<have> to call |
37 | 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 |
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. |
39 | will be started and you aio-operations will seem to hang. |
40 | |
|
|
41 | =cut |
|
|
42 | |
|
|
43 | =item aio_read($fh,$offset,$length, $data,$dataoffset,$callback) |
|
|
44 | aio_write($fh,$offset,$length, $data,$dataoffset,$callback) |
|
|
45 | |
|
|
46 | Reads or writes C<length> bytes from the specified C<fh> and C<offset> |
|
|
47 | into the scalar given by C<data> and offset C<dataoffset> and calls the |
|
|
48 | callback without the actual number of bytes read (or undef on error). |
|
|
49 | |
40 | |
50 | =item $fileno = Linux::AIO::poll_fileno |
41 | =item $fileno = Linux::AIO::poll_fileno |
51 | |
42 | |
52 | Return the request result pipe filehandle. This filehandle must be polled |
43 | Return the request result pipe filehandle. This filehandle must be polled |
53 | for reading. If the pipe becomes readable you have to call C<poll_cb>. |
44 | for reading. If the pipe becomes readable you have to call C<poll_cb>. |
… | |
… | |
66 | |
57 | |
67 | =item Linux::AIO::nreqs |
58 | =item Linux::AIO::nreqs |
68 | |
59 | |
69 | Returns the number of requests currently outstanding. |
60 | Returns the number of requests currently outstanding. |
70 | |
61 | |
|
|
62 | =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 | =item aio_read($fh,$offset,$length, $data,$dataoffset,$callback) |
|
|
72 | |
|
|
73 | =item aio_write($fh,$offset,$length, $data,$dataoffset,$callback) |
|
|
74 | |
|
|
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 | =item aio_stat($fh_or_path,$callback) |
|
|
80 | |
|
|
81 | =item aio_lstat($fh,$callback) |
|
|
82 | |
|
|
83 | 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 | |
|
|
87 | 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 | |
71 | =cut |
91 | =cut |
72 | |
92 | |
73 | END { |
93 | END { |
74 | max_parallel 0; |
94 | max_parallel 0; |
75 | } |
95 | } |
… | |
… | |
80 | |
100 | |
81 | =head1 BUGS |
101 | =head1 BUGS |
82 | |
102 | |
83 | This module has not yet been extensively tested. Watch out! |
103 | This module has not yet been extensively tested. Watch out! |
84 | |
104 | |
|
|
105 | - perl-threads/fork interaction poorly tested. |
|
|
106 | - aio_open gives a fd, but all other functions expect a filehandle. |
|
|
107 | |
85 | =head1 SEE ALSO |
108 | =head1 SEE ALSO |
86 | |
109 | |
87 | L<Coro>. |
110 | L<Coro>. |
88 | |
111 | |
89 | =head1 AUTHOR |
112 | =head1 AUTHOR |