… | |
… | |
281 | =head2 AIO REQUEST FUNCTIONS |
281 | =head2 AIO REQUEST FUNCTIONS |
282 | |
282 | |
283 | All the C<aio_*> calls are more or less thin wrappers around the syscall |
283 | All the C<aio_*> calls are more or less thin wrappers around the syscall |
284 | with the same name (sans C<aio_>). The arguments are similar or identical, |
284 | with the same name (sans C<aio_>). The arguments are similar or identical, |
285 | and they all accept an additional (and optional) C<$callback> argument |
285 | and they all accept an additional (and optional) C<$callback> argument |
286 | which must be a code reference. This code reference will get called with |
286 | which must be a code reference. This code reference will be called after |
287 | the syscall return code (e.g. most syscalls return C<-1> on error, unlike |
287 | the syscall has been executed in an asynchronous fashion. The results |
288 | perl, which usually delivers "false") as its sole argument after the given |
288 | of the request will be passed as arguments to the callback (and, if an |
289 | syscall has been executed asynchronously. |
289 | error occured, in C<$!>) - for most requests the syscall return code (e.g. |
|
|
290 | most syscalls return C<-1> on error, unlike perl, which usually delivers |
|
|
291 | "false"). |
|
|
292 | |
|
|
293 | Some requests (such as C<aio_readdir>) pass the actual results and |
|
|
294 | communicate failures by passing C<undef>. |
290 | |
295 | |
291 | All functions expecting a filehandle keep a copy of the filehandle |
296 | All functions expecting a filehandle keep a copy of the filehandle |
292 | internally until the request has finished. |
297 | internally until the request has finished. |
293 | |
298 | |
294 | All functions return request objects of type L<IO::AIO::REQ> that allow |
299 | All functions return request objects of type L<IO::AIO::REQ> that allow |
295 | further manipulation of those requests while they are in-flight. |
300 | further manipulation of those requests while they are in-flight. |
296 | |
301 | |
297 | The pathnames you pass to these routines I<should> be absolute. The |
302 | The pathnames you pass to these routines I<should> be absolute. The |
298 | reason for this is that at the time the request is being executed, the |
303 | reason for this is that at the time the request is being executed, the |
299 | current working directory could have changed. Alternatively, you can make |
304 | current working directory could have changed. Alternatively, you can |
300 | sure that you never change the current working directory anywhere in |
305 | make sure that you never change the current working directory anywhere |
301 | the program and then use relative paths. Lastly, you can take advantage |
306 | in the program and then use relative paths. You can also take advantage |
302 | of IO::AIOs working directory abstraction - see the description of the |
307 | of IO::AIOs working directory abstraction, that lets you specify paths |
|
|
308 | relative to some previously-opened "working directory object" - see the |
303 | C<IO::AIO::WD> class later in this document. |
309 | description of the C<IO::AIO::WD> class later in this document. |
304 | |
310 | |
305 | To encode pathnames as octets, either make sure you either: a) always pass |
311 | To encode pathnames as octets, either make sure you either: a) always pass |
306 | in filenames you got from outside (command line, readdir etc.) without |
312 | in filenames you got from outside (command line, readdir etc.) without |
307 | tinkering, b) are ASCII or ISO 8859-1, c) use the Encode module and encode |
313 | tinkering, b) are in your native filesystem encoding, c) use the Encode |
308 | your pathnames to the locale (or other) encoding in effect in the user |
314 | module and encode your pathnames to the locale (or other) encoding in |
309 | environment, d) use Glib::filename_from_unicode on unicode filenames or e) |
315 | effect in the user environment, d) use Glib::filename_from_unicode on |
310 | use something else to ensure your scalar has the correct contents. |
316 | unicode filenames or e) use something else to ensure your scalar has the |
|
|
317 | correct contents. |
311 | |
318 | |
312 | This works, btw. independent of the internal UTF-8 bit, which IO::AIO |
319 | This works, btw. independent of the internal UTF-8 bit, which IO::AIO |
313 | handles correctly whether it is set or not. |
320 | handles correctly whether it is set or not. |
314 | |
321 | |
315 | =over 4 |
322 | =over 4 |
… | |
… | |
967 | my $grp = aio_group $cb; |
974 | my $grp = aio_group $cb; |
968 | |
975 | |
969 | $maxreq = 4 if $maxreq <= 0; |
976 | $maxreq = 4 if $maxreq <= 0; |
970 | |
977 | |
971 | # get a wd object |
978 | # get a wd object |
972 | |
|
|
973 | aioreq_pri $pri; |
979 | aioreq_pri $pri; |
974 | add $grp aio_wd $path, sub { |
980 | add $grp aio_wd $path, sub { |
|
|
981 | $_[0] |
|
|
982 | or return $grp->result (); |
|
|
983 | |
975 | my $wd = [shift, "."]; |
984 | my $wd = [shift, "."]; |
976 | |
985 | |
977 | # stat once |
986 | # stat once |
978 | aioreq_pri $pri; |
987 | aioreq_pri $pri; |
979 | add $grp aio_stat $wd, sub { |
988 | add $grp aio_stat $wd, sub { |