ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/AIO.pm
(Generate patch)

Comparing Coro/Coro/AIO.pm (file contents):
Revision 1.2 by root, Mon Dec 26 19:26:52 2005 UTC vs.
Revision 1.3 by root, Mon Dec 26 21:54:44 2005 UTC

24the functions that expect a callback are being wrapped by this module. 24the functions that expect a callback are being wrapped by this module.
25 25
26The API is exactly the same as that of the corresponding IO::AIO routines, 26The API is exactly the same as that of the corresponding IO::AIO routines,
27except that you have to specify I<all> arguments I<except> the callback 27except that you have to specify I<all> arguments I<except> the callback
28argument. Instead the routines return the values normally passed to the 28argument. Instead the routines return the values normally passed to the
29callback. They also all have a prototype of C<@> currently, but that might
30change. Everything else, including C<$!> and perls stat cache, are set as 29callback. Everything else, including C<$!> and perls stat cache, are set
31expected after these functions return. 30as expected after these functions return.
32 31
33You can mix calls to C<IO::AIO> functions with calls to this module. You 32You can mix calls to C<IO::AIO> functions with calls to this module. You
33I<must not>, however, call these routines from within IO::AIO callbacks,
34as this causes a deadlock. Start a coro inside the callback instead.
35
34also can, but do not need to, call C<IO::AIO::poll_cb>, as this module 36You also can, but do not need to, call C<IO::AIO::poll_cb>, as this
35automatically installs an event watcher for the C<IO::AIO> file 37module automatically installs an event watcher for the C<IO::AIO> file
36descriptor. It uses the L<AnyEvent|AnyEvent> module for this, so please 38descriptor. It uses the L<AnyEvent|AnyEvent> module for this, so please
37refer to its documentation on how it selects an appropriate Event module. 39refer to its documentation on how it selects an appropriate Event module.
38 40
39For your convienience, here are the changed function signatures, for 41For your convienience, here are the changed function signatures, for
40documentation of these functions please have a look at L<IO::AIO|the 42documentation 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
90wrap $_ for qw(aio_sendfile aio_read aio_write aio_open aio_close aio_stat 101wrap $_ 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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines