… | |
… | |
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 |
275 | callback without the actual number of bytes read (or -1 on error, |
300 | callback without the actual number of bytes read (or -1 on error, |
276 | just like the syscall). |
301 | just like the syscall). |
277 | |
302 | |
278 | If $offset is undefined, then the current file offset will be used |
303 | If $offset is undefined, then the current file descriptor offset |
279 | (and updated), otherwise the file offset will not be changed by |
304 | will be used (and updated), otherwise the file descriptor offset |
280 | these calls. |
305 | will not be changed by these calls. |
281 | |
306 | |
282 | If $length is undefined in "aio_write", use the remaining length of |
307 | If $length is undefined in "aio_write", use the remaining length of |
283 | $data. |
308 | $data. |
284 | |
309 | |
285 | If $dataoffset is less than zero, it will be counted from the end of |
310 | If $dataoffset is less than zero, it will be counted from the end of |
… | |
… | |
851 | $oldmaxreqs = IO::AIO::max_outstanding $maxreqs |
876 | $oldmaxreqs = IO::AIO::max_outstanding $maxreqs |
852 | This is a very bad function to use in interactive programs because |
877 | This is a very bad function to use in interactive programs because |
853 | it blocks, and a bad way to reduce concurrency because it is |
878 | it blocks, and a bad way to reduce concurrency because it is |
854 | inexact: Better use an "aio_group" together with a feed callback. |
879 | inexact: Better use an "aio_group" together with a feed callback. |
855 | |
880 | |
856 | Sets the maximum number of outstanding requests to $nreqs. If you to |
881 | Sets the maximum number of outstanding requests to $nreqs. If you do |
857 | queue up more than this number of requests, the next call to the |
882 | queue up more than this number of requests, the next call to the |
858 | "poll_cb" (and "poll_some" and other functions calling "poll_cb") |
883 | "poll_cb" (and "poll_some" and other functions calling "poll_cb") |
859 | function will block until the limit is no longer exceeded. |
884 | function will block until the limit is no longer exceeded. |
860 | |
885 | |
861 | The default value is very large, so there is no practical limit on |
886 | The default value is very large, so there is no practical limit on |
… | |
… | |
907 | bytes of memory. In addition, stat requests need a stat buffer (possibly |
932 | bytes of memory. In addition, stat requests need a stat buffer (possibly |
908 | a few hundred bytes), readdir requires a result buffer and so on. Perl |
933 | a few hundred bytes), readdir requires a result buffer and so on. Perl |
909 | scalars and other data passed into aio requests will also be locked and |
934 | scalars and other data passed into aio requests will also be locked and |
910 | will consume memory till the request has entered the done state. |
935 | will consume memory till the request has entered the done state. |
911 | |
936 | |
912 | This is now awfully much, so queuing lots of requests is not usually a |
937 | This is not awfully much, so queuing lots of requests is not usually a |
913 | problem. |
938 | problem. |
914 | |
939 | |
915 | Per-thread usage: |
940 | Per-thread usage: |
916 | |
941 | |
917 | In the execution phase, some aio requests require more memory for |
942 | In the execution phase, some aio requests require more memory for |