… | |
… | |
24 | the functions that expect a callback are being wrapped by this module. |
24 | the functions that expect a callback are being wrapped by this module. |
25 | |
25 | |
26 | The API is exactly the same as that of the corresponding IO::AIO routines, |
26 | The API is exactly the same as that of the corresponding IO::AIO routines, |
27 | except that you have to specify I<all> arguments I<except> the callback |
27 | except that you have to specify I<all> arguments I<except> the callback |
28 | argument. Instead the routines return the values normally passed to the |
28 | argument. Instead the routines return the values normally passed to the |
29 | callback. They also all have a prototype of C<@> currently, but that might |
|
|
30 | change. Everything else, including C<$!> and perls stat cache, are set as |
29 | callback. Everything else, including C<$!> and perls stat cache, are set |
31 | expected after these functions return. |
30 | as expected after these functions return. |
32 | |
31 | |
33 | You can mix calls to C<IO::AIO> functions with calls to this module. You |
32 | You can mix calls to C<IO::AIO> functions with calls to this module. You |
|
|
33 | I<must not>, however, call these routines from within IO::AIO callbacks, |
|
|
34 | as this causes a deadlock. Start a coro inside the callback instead. |
|
|
35 | |
34 | also can, but do not need to, call C<IO::AIO::poll_cb>, as this module |
36 | You also can, but do not need to, call C<IO::AIO::poll_cb>, as this |
35 | automatically installs an event watcher for the C<IO::AIO> file |
37 | module automatically installs an event watcher for the C<IO::AIO> file |
36 | descriptor. It uses the L<AnyEvent|AnyEvent> module for this, so please |
38 | descriptor. It uses the L<AnyEvent|AnyEvent> module for this, so please |
37 | refer to its documentation on how it selects an appropriate Event module. |
39 | refer to its documentation on how it selects an appropriate Event module. |
38 | |
40 | |
39 | For your convienience, here are the changed function signatures, for |
41 | For your convienience, here are the changed function signatures, for |
40 | documentation of these functions please have a look at L<IO::AIO|the |
42 | documentation of these functions please have a look at L<IO::AIO|the |
… | |
… | |
65 | no strict 'refs'; |
67 | no strict 'refs'; |
66 | |
68 | |
67 | push @EXPORT, $sub; |
69 | push @EXPORT, $sub; |
68 | |
70 | |
69 | my $iosub = "IO::AIO::$sub"; |
71 | my $iosub = "IO::AIO::$sub"; |
|
|
72 | my $proto = prototype $iosub; |
70 | |
73 | |
71 | *$sub = sub { |
74 | $proto =~ s/;?\$$// or die "$iosub: unable to remove callback slot from prototype"; |
72 | my $current = $Coro::current; |
|
|
73 | my $stat; |
|
|
74 | my @res; |
|
|
75 | |
75 | |
76 | $iosub->(@_, sub { |
76 | eval qq{ |
77 | $stat = Coro::_aio_get_state; |
77 | #line 1 "Coro::AIO::$sub($proto)" |
|
|
78 | sub $sub($proto) { |
|
|
79 | my \$current = \$Coro::current; |
|
|
80 | my \$stat; |
78 | @res = @_; |
81 | my \@res; |
79 | $current->ready; |
|
|
80 | undef $current; |
|
|
81 | }); |
|
|
82 | |
82 | |
83 | Coro::schedule while $current; |
83 | push \@_, sub { |
|
|
84 | \$stat = Coro::_aio_get_state; |
|
|
85 | \@res = \@_; |
|
|
86 | \$current->ready; |
|
|
87 | undef \$current; |
|
|
88 | }; |
84 | |
89 | |
|
|
90 | &$iosub; |
|
|
91 | |
|
|
92 | Coro::schedule while \$current; |
|
|
93 | |
85 | Coro::_aio_set_state $stat; |
94 | Coro::_aio_set_state \$stat; |
86 | wantarray ? @res : $res[0] |
95 | wantarray ? \@res : \$res[0] |
|
|
96 | } |
87 | }; |
97 | }; |
|
|
98 | die if $@; |
88 | } |
99 | } |
89 | |
100 | |
90 | wrap $_ for qw(aio_sendfile aio_read aio_write aio_open aio_close aio_stat |
101 | wrap $_ for qw(aio_sendfile aio_read aio_write aio_open aio_close aio_stat |
91 | aio_lstat aio_unlink aio_rmdir aio_readdir aio_scandir |
102 | aio_lstat aio_unlink aio_rmdir aio_readdir aio_scandir |
92 | aio_symlink aio_fsync aio_fdatasync aio_readahead); |
103 | aio_symlink aio_fsync aio_fdatasync aio_readahead); |
… | |
… | |
109 | |
120 | |
110 | =item $status = aio_unlink $pathname |
121 | =item $status = aio_unlink $pathname |
111 | |
122 | |
112 | =item $status = aio_rmdir $pathname |
123 | =item $status = aio_rmdir $pathname |
113 | |
124 | |
114 | =item $entries = aio_readdir $pathname $callback->($entries) |
125 | =item $entries = aio_readdir $pathname |
115 | |
126 | |
116 | =item ($dirs, $nondirs) = aio_scandir $path, $maxreq |
127 | =item ($dirs, $nondirs) = aio_scandir $path, $maxreq |
117 | |
128 | |
118 | =item $status = aio_fsync $fh |
129 | =item $status = aio_fsync $fh |
119 | |
130 | |