… | |
… | |
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.5; |
68 | $VERSION = 1.6; |
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_readdir 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 | |
74 | require XSLoader; |
74 | require XSLoader; |
75 | XSLoader::load IO::AIO, $VERSION; |
75 | XSLoader::load IO::AIO, $VERSION; |
76 | } |
76 | } |
… | |
… | |
162 | aio_read $fh, 7, 15, $buffer, 0, sub { |
162 | aio_read $fh, 7, 15, $buffer, 0, sub { |
163 | $_[0] > 0 or die "read error: $!"; |
163 | $_[0] > 0 or die "read error: $!"; |
164 | print "read $_[0] bytes: <$buffer>\n"; |
164 | print "read $_[0] bytes: <$buffer>\n"; |
165 | }; |
165 | }; |
166 | |
166 | |
|
|
167 | =item aio_sendfile $out_fh, $in_fh, $in_offset, $length, $callback |
|
|
168 | |
|
|
169 | Tries to copy C<$length> bytes from C<$in_fh> to C<$out_fh>. It starts |
|
|
170 | reading at byte offset C<$in_offset>, and starts writing at the current |
|
|
171 | file offset of C<$out_fh>. Because of that, it is not safe to issue more |
|
|
172 | than one C<aio_sendfile> per C<$out_fh>, as they will interfere with each |
|
|
173 | other. |
|
|
174 | |
|
|
175 | This call tries to make use of a native C<sendfile> syscall to provide |
|
|
176 | zero-copy operation. For this to work, C<$out_fh> should refer to a |
|
|
177 | socket, and C<$in_fh> should refer to mmap'able file. |
|
|
178 | |
|
|
179 | If the native sendfile call fails or is not implemented, it will be |
|
|
180 | emulated, so you can call C<aio_sendfile> on any type of filehandle |
|
|
181 | regardless of the limitations of the operating system. |
|
|
182 | |
|
|
183 | Please note, however, that C<aio_sendfile> can read more bytes from |
|
|
184 | C<$in_fh> than are written, and there is no way to find out how many |
|
|
185 | bytes have been read from C<aio_sendfile> alone, as C<aio_sendfile> only |
|
|
186 | provides the number of bytes written to C<$out_fh>. Only if the result |
|
|
187 | value equals C<$length> one can assume that C<$length> bytes have been |
|
|
188 | read. |
|
|
189 | |
167 | =item aio_readahead $fh,$offset,$length, $callback |
190 | =item aio_readahead $fh,$offset,$length, $callback |
168 | |
191 | |
169 | C<aio_readahead> populates the page cache with data from a file so that |
192 | C<aio_readahead> populates the page cache with data from a file so that |
170 | subsequent reads from that file will not block on disk I/O. The C<$offset> |
193 | subsequent reads from that file will not block on disk I/O. The C<$offset> |
171 | argument specifies the starting point from which data is to be read and |
194 | argument specifies the starting point from which data is to be read and |
… | |
… | |
208 | =item aio_rmdir $pathname, $callback |
231 | =item aio_rmdir $pathname, $callback |
209 | |
232 | |
210 | Asynchronously rmdir (delete) a directory and call the callback with the |
233 | Asynchronously rmdir (delete) a directory and call the callback with the |
211 | result code. |
234 | result code. |
212 | |
235 | |
|
|
236 | =item aio_readdir $pathname $callback |
|
|
237 | |
|
|
238 | Unlike the POSIX call of the same name, C<aio_readdir> reads an entire |
|
|
239 | directory (i.e. opendir + readdir + closedir). The entries will not be |
|
|
240 | sorted, and will B<NOT> include the C<.> and C<..> entries. |
|
|
241 | |
|
|
242 | The callback a single argument which is either C<undef> or an array-ref |
|
|
243 | with the filenames. |
|
|
244 | |
213 | =item aio_fsync $fh, $callback |
245 | =item aio_fsync $fh, $callback |
214 | |
246 | |
215 | Asynchronously call fsync on the given filehandle and call the callback |
247 | Asynchronously call fsync on the given filehandle and call the callback |
216 | with the fsync result code. |
248 | with the fsync result code. |
217 | |
249 | |