--- IO-AIO/README 2007/09/24 19:28:50 1.25 +++ IO-AIO/README 2007/10/06 14:05:37 1.27 @@ -260,13 +260,38 @@ aio_close $fh, $callback->($status) Asynchronously close a file and call the callback with the result - code. *WARNING:* although accepted, you should not pass in a perl - filehandle here, as perl will likely close the file descriptor - another time when the filehandle is destroyed. Normally, you can - safely call perls "close" or just let filehandles go out of scope. + code. - This is supposed to be a bug in the API, so that might change. It's - therefore best to avoid this function. + Unfortunately, you can't do this to perl. Perl *insists* very + strongly on closing the file descriptor associated with the + filehandle itself. Here is what aio_close will try: + + 1. dup()licate the fd + 2. asynchronously close() the duplicated fd + 3. dup()licate the fd once more + 4. let perl close() the filehandle + 5. asynchronously close the duplicated fd + + The idea is that the first close() flushes stuff to disk that + closing an fd will flush, so when perl closes the fd, nothing much + will need to be flushed. The second async. close() will then flush + stuff to disk that closing the last fd to the file will flush. + + Just FYI, SuSv3 has this to say on close: + + All outstanding record locks owned by the process on the file + associated with the file descriptor shall be removed. + + If fildes refers to a socket, close() shall cause the socket to be + destroyed. ... close() shall block for up to the current linger + interval until all data is transmitted. + [this actually sounds like a specification bug, but who knows] + + And at least Linux additionally actually flushes stuff on every + close, even when the file itself is still open. + + Sounds enourmously inefficient and complicated? Yes... please show + me how to nuke perl's fd out of existence... aio_read $fh,$offset,$length, $data,$dataoffset, $callback->($retval) aio_write $fh,$offset,$length, $data,$dataoffset, $callback->($retval)