1AIO(3) User Contributed Perl Documentation AIO(3)
2
3
4
6 Coro::AIO - truly asynchronous file and directory I/O
7
9 use Coro::AIO;
10
11 # can now use any of the aio requests your IO::AIO module supports.
12
13 # read 1MB of /etc/passwd, without blocking other coroutines
14 my $fh = aio_open "/etc/passwd", O_RDONLY, 0
15 or die "/etc/passwd: $!";
16 aio_read $fh, 0, 1_000_000, my $buf, 0
17 or die "aio_read: $!";
18 aio_close $fh;
19
21 This module is an AnyEvent user, you need to make sure that you use and
22 run a supported event loop.
23
24 This module implements a thin wrapper around IO::AIO. All of the
25 functions that expect a callback are being wrapped by this module.
26
27 The API is exactly the same as that of the corresponding IO::AIO
28 routines, except that you have to specify all arguments, even the ones
29 optional in IO::AIO, except the callback argument. Instead of calling a
30 callback, the routines return the values normally passed to the
31 callback. Everything else, including $! and perls stat cache, are set
32 as expected after these functions return.
33
34 You can mix calls to "IO::AIO" functions with calls to this module. You
35 must not, however, call these routines from within IO::AIO callbacks,
36 as this causes a deadlock. Start a coro inside the callback instead.
37
38 This module also loads AnyEvent::AIO to integrate into the event loop
39 in use, so please refer to its (and AnyEvent's) documentation on how it
40 selects an appropriate event module.
41
42 All other functions exported by default by IO::AIO (e.g. "aioreq_pri")
43 will be exported by default by Coro::AIO, too.
44
45 Functions that can be optionally imported from IO::AIO can be imported
46 from Coro::AIO or can be called directly, e.g. "Coro::AIO::nreqs".
47
48 You cannot specify priorities with "aioreq_pri" if your coroutine has a
49 non-zero priority, as this module overwrites the request priority with
50 the current coroutine priority in that case.
51
52 For your convenience, here are the changed function signatures for most
53 of the requests, for documentation of these functions please have a
54 look at IO::AIO. Note that requests added by newer versions of IO::AIO
55 will be automatically wrapped as well.
56
57 @results = aio_wait $req
58 This is not originally an IO::AIO request: what it does is to wait
59 for $req to finish and return the results. This is most useful with
60 "aio_group" requests.
61
62 Is currently implemented by replacing the $req callback (and is
63 very much like a wrapper around "$req->cb ()").
64
65 $fh = aio_open $pathname, $flags, $mode
66 $status = aio_close $fh
67 $retval = aio_read $fh,$offset,$length, $data,$dataoffset
68 $retval = aio_write $fh,$offset,$length, $data,$dataoffset
69 $retval = aio_sendfile $out_fh, $in_fh, $in_offset, $length
70 $retval = aio_readahead $fh,$offset,$length
71 $status = aio_stat $fh_or_path
72 $status = aio_lstat $fh
73 $status = aio_unlink $pathname
74 $status = aio_rmdir $pathname
75 $entries = aio_readdir $pathname
76 ($dirs, $nondirs) = aio_scandir $path, $maxreq
77 $status = aio_fsync $fh
78 $status = aio_fdatasync $fh
79 ... = aio_xxx ...
80 Any additional aio requests follow the same scheme: same parameters
81 except you must not specify a callback but instead get the callback
82 arguments as return values.
83
85 Coro::Socket and Coro::Handle for non-blocking socket operation.
86
88 Marc A. Lehmann <schmorp@schmorp.de>
89 http://software.schmorp.de/pkg/Coro.html
90
91
92
93perl v5.30.1 2020-01-29 AIO(3)