… | |
… | |
63 | use base 'Exporter'; |
63 | use base 'Exporter'; |
64 | |
64 | |
65 | use Fcntl (); |
65 | use Fcntl (); |
66 | |
66 | |
67 | BEGIN { |
67 | BEGIN { |
68 | $VERSION = 1.1; |
68 | $VERSION = 1.4; |
69 | |
69 | |
70 | @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat aio_unlink |
70 | @EXPORT = qw(aio_read aio_write aio_open aio_close aio_stat aio_lstat aio_unlink |
71 | aio_rmdir aio_symlink aio_fsync aio_fdatasync aio_readahead); |
71 | aio_rmdir aio_symlink aio_fsync aio_fdatasync aio_readahead); |
72 | @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel max_outstanding nreqs); |
72 | @EXPORT_OK = qw(poll_fileno poll_cb min_parallel max_parallel max_outstanding nreqs); |
73 | |
73 | |
… | |
… | |
88 | syscall has been executed asynchronously. |
88 | syscall has been executed asynchronously. |
89 | |
89 | |
90 | All functions expecting a filehandle keep a copy of the filehandle |
90 | All functions expecting a filehandle keep a copy of the filehandle |
91 | internally until the request has finished. |
91 | internally until the request has finished. |
92 | |
92 | |
93 | The filenames you pass to these routines I<must> be absolute. The reason |
93 | The pathnames you pass to these routines I<must> be absolute and |
94 | for this is that at the time the request is being executed, the current |
94 | encoded in byte form. The reason for the former is that at the time the |
95 | working directory could have changed. Alternatively, you can make sure |
95 | request is being executed, the current working directory could have |
96 | that you never change the current working directory. |
96 | changed. Alternatively, you can make sure that you never change the |
|
|
97 | current working directory. |
|
|
98 | |
|
|
99 | To encode pathnames to byte form, either make sure you either: a) |
|
|
100 | always pass in filenames you got from outside (command line, readdir |
|
|
101 | etc.), b) are ASCII or ISO 8859-1, c) use the Encode module and encode |
|
|
102 | your pathnames to the locale (or other) encoding in effect in the user |
|
|
103 | environment, d) use Glib::filename_from_unicode on unicode filenames or e) |
|
|
104 | use something else. |
97 | |
105 | |
98 | =over 4 |
106 | =over 4 |
99 | |
107 | |
100 | =item aio_open $pathname, $flags, $mode, $callback |
108 | =item aio_open $pathname, $flags, $mode, $callback |
101 | |
109 | |
… | |
… | |
142 | Reads or writes C<length> bytes from the specified C<fh> and C<offset> |
150 | Reads or writes C<length> bytes from the specified C<fh> and C<offset> |
143 | into the scalar given by C<data> and offset C<dataoffset> and calls the |
151 | into the scalar given by C<data> and offset C<dataoffset> and calls the |
144 | callback without the actual number of bytes read (or -1 on error, just |
152 | callback without the actual number of bytes read (or -1 on error, just |
145 | like the syscall). |
153 | like the syscall). |
146 | |
154 | |
|
|
155 | The C<$data> scalar I<MUST NOT> be modified in any way while the request |
|
|
156 | is outstanding. Modifying it can result in segfaults or WW3 (if the |
|
|
157 | necessary/optional hardware is installed). |
|
|
158 | |
147 | Example: Read 15 bytes at offset 7 into scalar C<$buffer>, starting at |
159 | Example: Read 15 bytes at offset 7 into scalar C<$buffer>, starting at |
148 | offset C<0> within the scalar: |
160 | offset C<0> within the scalar: |
149 | |
161 | |
150 | aio_read $fh, 7, 15, $buffer, 0, sub { |
162 | aio_read $fh, 7, 15, $buffer, 0, sub { |
151 | $_[0] > 0 or die "read error: $!"; |
163 | $_[0] > 0 or die "read error: $!"; |
… | |
… | |
341 | |
353 | |
342 | 1; |
354 | 1; |
343 | |
355 | |
344 | =head2 FORK BEHAVIOUR |
356 | =head2 FORK BEHAVIOUR |
345 | |
357 | |
346 | IO::AIO handles all outstanding AIO requests before the fork, destroys all |
358 | Before the fork IO::AIO enters a quiescent state where no requests can be |
347 | AIO threads, and recreates them in both the parent and the child after the |
359 | added in other threads and no results will be processed. After the fork |
348 | fork. |
360 | the parent simply leaves the quiescent state and continues request/result |
349 | |
361 | processing, while the child clears the request/result queue and starts the |
|
|
362 | same number of threads as were in use by the parent. |
350 | |
363 | |
351 | =head1 SEE ALSO |
364 | =head1 SEE ALSO |
352 | |
365 | |
353 | L<Coro>, L<Linux::AIO>. |
366 | L<Coro>, L<Linux::AIO>. |
354 | |
367 | |