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.4 by root, Tue Oct 24 03:50:16 2006 UTC vs.
Revision 1.5 by root, Wed Nov 1 22:02:45 2006 UTC

33You also can, but do not need to, call C<IO::AIO::poll_cb>, as this 33You also can, but do not need to, call C<IO::AIO::poll_cb>, as this
34module automatically installs an event watcher for the C<IO::AIO> file 34module automatically installs an event watcher for the C<IO::AIO> file
35descriptor. It uses the L<AnyEvent|AnyEvent> module for this, so please 35descriptor. It uses the L<AnyEvent|AnyEvent> module for this, so please
36refer to its documentation on how it selects an appropriate Event module. 36refer to its documentation on how it selects an appropriate Event module.
37 37
38All other functions exported by default by IO::AIO (e.g. C<aioreq_pri>)
39will be exported by default by Coro::AIO, too.
40
41Functions that can be optionally imported from IO::AIO can be imported
42from Coro::AIO or can be called directly, e.g. C<Coro::AIO::nreqs>.
43
38For your convienience, here are the changed function signatures, for 44For your convienience, here are the changed function signatures for most
39documentation of these functions please have a look at L<IO::AIO|the 45of the requests, for documentation of these functions please have a look
40IO::AIO manual>. 46at L<IO::AIO|the IO::AIO manual>.
41 47
42=over 4 48=over 4
43 49
44=cut 50=cut
45 51
46package Coro::AIO; 52package Coro::AIO;
47 53
48use strict; 54use strict 'subs';
49 55
50use Coro (); 56use Coro ();
51use AnyEvent; 57use AnyEvent;
52use IO::AIO (); 58use IO::AIO ();
53 59
54use base Exporter::; 60use base Exporter::;
55 61
56our $FH; open $FH, "<&=" . IO::AIO::poll_fileno; 62our $FH; open $FH, "<&=" . IO::AIO::poll_fileno;
57our $WATCHER = AnyEvent->io (fh => $FH, poll => 'r', cb => sub { IO::AIO::poll_cb }); 63our $WATCHER = AnyEvent->io (fh => $FH, poll => 'r', cb => sub { IO::AIO::poll_cb });
58 64
59our @EXPORT; 65our @EXPORT = @IO::AIO::EXPORT;
66our @EXPORT_OK = @IO::AIO::EXPORT_OK;
67our $AUTOLOAD;
60 68
61sub wrap($) { 69{
62 my ($sub) = @_; 70 my @reqs = @IO::AIO::AIO_REQ ? @IO::AIO::AIO_REQ : @EXPORT;
71 my %reqs = map +($_ => 1), @reqs;
63 72
64 no strict 'refs'; 73 eval
65 74 join "",
66 push @EXPORT, $sub; 75 map "sub $_(" . (prototype "IO::AIO::$_") . ");",
67 76 grep !$reqs{$_},
68 my $iosub = "IO::AIO::$sub"; 77 @EXPORT, @EXPORT_OK;
69 my $proto = prototype $iosub;
70 78
71 $proto =~ s/;?\$$// or die "$iosub: unable to remove callback slot from prototype"; 79 for my $sub (@reqs) {
80 push @EXPORT, $sub;
81
82 my $iosub = "IO::AIO::$sub";
83 my $proto = prototype $iosub;
72 84
85 $proto =~ s/;?\$$// or die "$iosub: unable to remove callback slot from prototype";
86
73 eval qq{ 87 eval qq{
74#line 1 "Coro::AIO::$sub($proto)" 88#line 1 "Coro::AIO::$sub($proto)"
75 sub $sub($proto) { 89 sub $sub($proto) {
76 my \$current = \$Coro::current; 90 my \$current = \$Coro::current;
77 my \$stat; 91 my \$stat;
78 my \@res; 92 my \@res;
79 93
80 push \@_, sub { 94 push \@_, sub {
81 \$stat = Coro::_aio_get_state; 95 \$stat = Coro::_aio_get_state;
82 \@res = \@_; 96 \@res = \@_;
83 \$current->ready; 97 \$current->ready;
84 undef \$current; 98 undef \$current;
85 }; 99 };
86 100
87 &$iosub; 101 &$iosub;
88 102
89 Coro::schedule while \$current; 103 Coro::schedule while \$current;
90 104
91 Coro::_aio_set_state \$stat; 105 Coro::_aio_set_state \$stat;
92 wantarray ? \@res : \$res[0] 106 wantarray ? \@res : \$res[0]
107 }
93 } 108 };
94 };
95 die if $@; 109 die if $@;
110 }
96} 111}
97 112
98wrap $_ for @IO::AIO::AIO_REQ 113sub AUTOLOAD {
99 ? @IO::AIO::AIO_REQ 114 (my $func = $AUTOLOAD) =~ s/^.*:://;
100 : @IO::AIO::EXPORT; 115 *$AUTOLOAD = \&{"IO::AIO::$func"};
116 goto &$AUTOLOAD;
117}
101 118
102=item $fh = aio_open $pathname, $flags, $mode 119=item $fh = aio_open $pathname, $flags, $mode
103 120
104=item $status = aio_close $fh 121=item $status = aio_close $fh
105 122

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines