… | |
… | |
260 | |
260 | |
261 | aio_close $fh, $callback->($status) |
261 | aio_close $fh, $callback->($status) |
262 | Asynchronously close a file and call the callback with the result |
262 | Asynchronously close a file and call the callback with the result |
263 | code. |
263 | code. |
264 | |
264 | |
265 | Unlike the other functions operating on files, this function uses |
265 | Unfortunately, you can't do this to perl. Perl *insists* very |
266 | the PerlIO layer to close the filehandle. The reason is that the |
266 | strongly on closing the file descriptor associated with the |
267 | PerlIO API insists on closing the underlying fd itself, no matter |
267 | filehandle itself. Here is what aio_close will try: |
268 | what, and doesn't allow modifications to the fd. Unfortunately, it |
|
|
269 | is not clear that you can call PerlIO from different threads |
|
|
270 | (actually, its quite clear that this won't work in some cases), so |
|
|
271 | while it likely works perfectly with simple file handles (such as |
|
|
272 | the ones created by "aio_open") it might fail in interesting ways |
|
|
273 | for others. |
|
|
274 | |
268 | |
275 | Having said that, aio_close tries to clean up the filehandle as much |
269 | 1. dup()licate the fd |
276 | as possible before handing it to an io thread, and generally does |
270 | 2. asynchronously close() the duplicated fd |
277 | work. |
271 | 3. dup()licate the fd once more |
|
|
272 | 4. let perl close() the filehandle |
|
|
273 | 5. asynchronously close the duplicated fd |
|
|
274 | |
|
|
275 | The idea is that the first close() flushes stuff to disk that |
|
|
276 | closing an fd will flush, so when perl closes the fd, nothing much |
|
|
277 | will need to be flushed. The second async. close() will then flush |
|
|
278 | stuff to disk that closing the last fd to the file will flush. |
|
|
279 | |
|
|
280 | Just FYI, SuSv3 has this to say on close: |
|
|
281 | |
|
|
282 | All outstanding record locks owned by the process on the file |
|
|
283 | associated with the file descriptor shall be removed. |
|
|
284 | |
|
|
285 | If fildes refers to a socket, close() shall cause the socket to be |
|
|
286 | destroyed. ... close() shall block for up to the current linger |
|
|
287 | interval until all data is transmitted. |
|
|
288 | [this actually sounds like a specification bug, but who knows] |
|
|
289 | |
|
|
290 | And at least Linux additionally actually flushes stuff on every |
|
|
291 | close, even when the file itself is still open. |
|
|
292 | |
|
|
293 | Sounds enourmously inefficient and complicated? Yes... please show |
|
|
294 | me how to nuke perl's fd out of existence... |
278 | |
295 | |
279 | aio_read $fh,$offset,$length, $data,$dataoffset, $callback->($retval) |
296 | aio_read $fh,$offset,$length, $data,$dataoffset, $callback->($retval) |
280 | aio_write $fh,$offset,$length, $data,$dataoffset, $callback->($retval) |
297 | aio_write $fh,$offset,$length, $data,$dataoffset, $callback->($retval) |
281 | Reads or writes $length bytes from the specified $fh and $offset |
298 | Reads or writes $length bytes from the specified $fh and $offset |
282 | into the scalar given by $data and offset $dataoffset and calls the |
299 | into the scalar given by $data and offset $dataoffset and calls the |