… | |
… | |
129 | |
129 | |
130 | aio_read $fh, 7, 15, $buffer, 0, sub { |
130 | aio_read $fh, 7, 15, $buffer, 0, sub { |
131 | $_[0] > 0 or die "read error: $!"; |
131 | $_[0] > 0 or die "read error: $!"; |
132 | print "read $_[0] bytes: <$buffer>\n"; |
132 | print "read $_[0] bytes: <$buffer>\n"; |
133 | }; |
133 | }; |
|
|
134 | |
|
|
135 | aio_sendfile $out_fh, $in_fh, $in_offset, $length, $callback |
|
|
136 | Tries to copy $length bytes from $in_fh to $out_fh. It starts |
|
|
137 | reading at byte offset $in_offset, and starts writing at the current |
|
|
138 | file offset of $out_fh. Because of that, it is not safe to issue |
|
|
139 | more than one "aio_sendfile" per $out_fh, as they will interfere |
|
|
140 | with each other. |
|
|
141 | |
|
|
142 | This call tries to make use of a native "sendfile" syscall to |
|
|
143 | provide zero-copy operation. For this to work, $out_fh should refer |
|
|
144 | to a socket, and $in_fh should refer to mmap'able file. |
|
|
145 | |
|
|
146 | If the native sendfile call fails or is not implemented, it will be |
|
|
147 | emulated, so you can call "aio_sendfile" on any type of filehandle |
|
|
148 | regardless of the limitations of the operating system. |
|
|
149 | |
|
|
150 | Please note, however, that "aio_sendfile" can read more bytes from |
|
|
151 | $in_fh than are written, and there is no way to find out how many |
|
|
152 | bytes have been read from "aio_sendfile" alone, as "aio_sendfile" |
|
|
153 | only provides the number of bytes written to $out_fh. Only if the |
|
|
154 | result value equals $length one can assume that $length bytes have |
|
|
155 | been read. |
134 | |
156 | |
135 | aio_readahead $fh,$offset,$length, $callback |
157 | aio_readahead $fh,$offset,$length, $callback |
136 | "aio_readahead" populates the page cache with data from a file so |
158 | "aio_readahead" populates the page cache with data from a file so |
137 | that subsequent reads from that file will not block on disk I/O. The |
159 | that subsequent reads from that file will not block on disk I/O. The |
138 | $offset argument specifies the starting point from which data is to |
160 | $offset argument specifies the starting point from which data is to |