… | |
… | |
258 | } |
258 | } |
259 | }; |
259 | }; |
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. *WARNING:* although accepted, you should not pass in a perl |
263 | code. |
264 | filehandle here, as perl will likely close the file descriptor |
|
|
265 | another time when the filehandle is destroyed. Normally, you can |
|
|
266 | safely call perls "close" or just let filehandles go out of scope. |
|
|
267 | |
264 | |
268 | This is supposed to be a bug in the API, so that might change. It's |
265 | Unfortunately, you can't do this to perl. Perl *insists* very |
269 | therefore best to avoid this function. |
266 | strongly on closing the file descriptor associated with the |
|
|
267 | filehandle itself. Here is what aio_close will try: |
|
|
268 | |
|
|
269 | 1. dup()licate the fd |
|
|
270 | 2. asynchronously close() the duplicated fd |
|
|
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... |
270 | |
295 | |
271 | aio_read $fh,$offset,$length, $data,$dataoffset, $callback->($retval) |
296 | aio_read $fh,$offset,$length, $data,$dataoffset, $callback->($retval) |
272 | aio_write $fh,$offset,$length, $data,$dataoffset, $callback->($retval) |
297 | aio_write $fh,$offset,$length, $data,$dataoffset, $callback->($retval) |
273 | Reads or writes $length bytes from the specified $fh and $offset |
298 | Reads or writes $length bytes from the specified $fh and $offset |
274 | 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 |