… | |
… | |
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 filehandles regardless of |
|
|
181 | the limitations of the OS. |
|
|
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 form C<aio_sendfile> alone, as C<aio_sendfile> only |
|
|
186 | provides the number of bytes written to C<$out_fh>. Only if the return |
|
|
187 | value (the value provided to the callback) equals C<$length> one can |
|
|
188 | assume that C<$length> bytes have been 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 |