line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package POE::Loop::AnyEvent; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$POE::Loop::AnyEvent::VERSION = '0.004'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
# vim: ts=2 sw=2 expandtab |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#ABSTRACT: AnyEvent event loop support for POE |
8
|
|
|
|
|
|
|
|
9
|
33
|
|
|
33
|
|
3384855
|
use strict; |
|
33
|
|
|
|
|
112
|
|
|
33
|
|
|
|
|
1492
|
|
10
|
33
|
|
|
33
|
|
200
|
use warnings; |
|
33
|
|
|
|
|
65
|
|
|
33
|
|
|
|
|
1377
|
|
11
|
|
|
|
|
|
|
|
12
|
33
|
|
|
33
|
|
31704
|
use POE::Loop::PerlSignals; |
|
33
|
|
|
|
|
35228
|
|
|
33
|
|
|
|
|
1253
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package # Hide from Pause |
15
|
|
|
|
|
|
|
POE::Kernel; |
16
|
|
|
|
|
|
|
|
17
|
33
|
|
|
33
|
|
349
|
use strict; |
|
33
|
|
|
|
|
74
|
|
|
33
|
|
|
|
|
998
|
|
18
|
33
|
|
|
33
|
|
176
|
use warnings; |
|
33
|
|
|
|
|
78
|
|
|
33
|
|
|
|
|
936
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# According to Paul Evans (IO::Async guy) we should make AnyEvent try |
21
|
|
|
|
|
|
|
# and detect a loop early before it retardedly tries to load AE::Impl::POE |
22
|
33
|
|
|
33
|
|
59658
|
use AnyEvent; |
|
33
|
|
|
|
|
206588
|
|
|
33
|
|
|
|
|
2891
|
|
23
|
|
|
|
|
|
|
BEGIN { |
24
|
|
|
|
|
|
|
# Remove POE from AnyEvent's list of available models. AnyEvent may |
25
|
|
|
|
|
|
|
# try to load POE since it's available. This wreaks havoc on |
26
|
|
|
|
|
|
|
# things. Common problems include (a) unexpected re-entrancy in POE |
27
|
|
|
|
|
|
|
# initialization; (b) deep recursion as POE tries to dispatch its |
28
|
|
|
|
|
|
|
# events with itself. |
29
|
|
|
|
|
|
|
|
30
|
33
|
|
|
33
|
|
99
|
@AnyEvent::models = grep { $_->[1] !~ /\bPOE\b/ } @AnyEvent::models; |
|
462
|
|
|
|
|
1408
|
|
31
|
33
|
|
|
|
|
173
|
AnyEvent::detect(); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
33
|
|
|
33
|
|
221448
|
use constant ANYEVENT_6 => $AnyEvent::VERSION >= 6; |
|
33
|
|
|
|
|
77
|
|
|
33
|
|
|
|
|
38232
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $loop; |
37
|
|
|
|
|
|
|
my $_watcher_timer; |
38
|
|
|
|
|
|
|
my $_idle_timer; |
39
|
|
|
|
|
|
|
my %signal_watcher; |
40
|
|
|
|
|
|
|
my %handle_watchers; |
41
|
|
|
|
|
|
|
|
42
|
49
|
|
|
49
|
0
|
1518777
|
sub loop_initialize { |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub loop_finalize { |
46
|
45
|
|
|
45
|
0
|
22015
|
my $self = shift; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
0
|
0
|
0
|
sub loop_do_timeslice { |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub loop_run { |
53
|
45
|
|
|
45
|
0
|
6605977
|
my $self = shift; |
54
|
|
|
|
|
|
|
# Avoid a hang when trying to run an idle Kernel. |
55
|
45
|
|
|
|
|
700
|
$self->_test_if_kernel_is_idle(); |
56
|
45
|
|
|
|
|
12200
|
( $loop = AnyEvent->condvar )->recv; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub loop_halt { |
60
|
45
|
|
|
45
|
0
|
626104
|
$loop->send; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub loop_watch_filehandle { |
64
|
504
|
|
|
504
|
0
|
1383359
|
my ($self, $handle, $mode) = @_; |
65
|
504
|
|
|
|
|
1908
|
my $fileno = fileno($handle); |
66
|
|
|
|
|
|
|
|
67
|
504
|
100
|
|
|
|
2192
|
if ($mode == MODE_RD) { |
|
|
50
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
$handle_watchers{watch_r}{$handle} = AnyEvent->io( |
70
|
|
|
|
|
|
|
fh => $handle, |
71
|
|
|
|
|
|
|
poll => 'r', |
72
|
|
|
|
|
|
|
cb => |
73
|
|
|
|
|
|
|
sub { |
74
|
271
|
|
|
271
|
|
9155133
|
my $self = $poe_kernel; |
75
|
271
|
|
|
|
|
1506
|
if (TRACE_FILES) { |
76
|
271
|
|
|
|
|
1498
|
POE::Kernel::_warn " got read callback for $handle"; |
77
|
|
|
|
|
|
|
} |
78
|
271
|
|
|
|
|
42490
|
$self->_data_handle_enqueue_ready(MODE_RD, $fileno); |
79
|
271
|
|
|
|
|
558855
|
$self->_test_if_kernel_is_idle(); |
80
|
283
|
|
|
|
|
38388
|
return 0; |
81
|
|
|
|
|
|
|
}, |
82
|
208
|
|
|
|
|
3643
|
); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
elsif ($mode == MODE_WR) { |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
$handle_watchers{watch_w}{$handle} = AnyEvent->io( |
88
|
|
|
|
|
|
|
fh => $handle, |
89
|
|
|
|
|
|
|
poll => 'w', |
90
|
|
|
|
|
|
|
cb => |
91
|
|
|
|
|
|
|
sub { |
92
|
213
|
|
|
213
|
|
2302
|
my $self = $poe_kernel; |
93
|
213
|
|
|
|
|
396
|
if (TRACE_FILES) { |
94
|
213
|
|
|
|
|
10722
|
POE::Kernel::_warn " got write callback for $handle"; |
95
|
|
|
|
|
|
|
} |
96
|
213
|
|
|
|
|
14862
|
$self->_data_handle_enqueue_ready(MODE_WR, $fileno); |
97
|
157
|
|
|
|
|
377442
|
$self->_test_if_kernel_is_idle(); |
98
|
157
|
|
|
|
|
37999
|
return 0; |
99
|
|
|
|
|
|
|
}, |
100
|
229
|
|
|
|
|
2946
|
); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
else { |
104
|
0
|
|
|
|
|
0
|
confess "AnyEvent::io does not support expedited filehandles"; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub loop_ignore_filehandle { |
109
|
499
|
|
|
499
|
0
|
429667
|
my ($self, $handle, $mode) = @_; |
110
|
499
|
|
|
|
|
1148
|
my $fileno = fileno($handle); |
111
|
|
|
|
|
|
|
|
112
|
499
|
50
|
|
|
|
2330
|
if ( $mode == MODE_EX ) { |
113
|
0
|
|
|
|
|
0
|
confess "AnyEvent::io does not support expedited filehandles"; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
499
|
100
|
|
|
|
11131
|
delete $handle_watchers{ $mode == MODE_RD ? 'watch_r' : 'watch_w' }{$handle}; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub loop_pause_filehandle { |
120
|
239
|
|
|
239
|
0
|
142452
|
shift->loop_ignore_filehandle(@_); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub loop_resume_filehandle { |
124
|
209
|
|
|
209
|
0
|
336663
|
shift->loop_watch_filehandle(@_); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub loop_resume_time_watcher { |
128
|
1017
|
|
|
1017
|
0
|
1518091
|
my ($self, $next_time) = @_; |
129
|
1017
|
50
|
|
|
|
3936
|
return unless defined $next_time; |
130
|
1017
|
|
|
|
|
3864
|
$next_time -= time(); |
131
|
1017
|
100
|
|
|
|
3355
|
$next_time = 0 if $next_time < 0; |
132
|
1017
|
|
|
|
|
6764
|
$_watcher_timer = AnyEvent->timer( after => $next_time, cb => \&_loop_event_callback); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub loop_reset_time_watcher { |
136
|
341
|
|
|
341
|
0
|
2988882
|
my ($self, $next_time) = @_; |
137
|
341
|
|
|
|
|
1115
|
undef $_watcher_timer; |
138
|
341
|
|
|
|
|
2688
|
$self->loop_resume_time_watcher($next_time); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub _loop_resume_timer { |
142
|
320
|
|
|
320
|
|
6890
|
undef $_idle_timer; |
143
|
320
|
|
|
|
|
2026
|
$poe_kernel->loop_resume_time_watcher($poe_kernel->get_next_event_time()); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
155
|
|
|
155
|
0
|
1228480
|
sub loop_pause_time_watcher { |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# Event callback to dispatch pending events. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub _loop_event_callback { |
152
|
443
|
|
|
443
|
|
18773165
|
my $self = $poe_kernel; |
153
|
|
|
|
|
|
|
|
154
|
443
|
|
|
|
|
4177
|
$self->_data_ev_dispatch_due(); |
155
|
443
|
|
|
|
|
8154
|
$self->_test_if_kernel_is_idle(); |
156
|
|
|
|
|
|
|
|
157
|
443
|
|
|
|
|
155489
|
undef $_watcher_timer; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
# Register the next timeout if there are events left. |
160
|
443
|
100
|
|
|
|
5569
|
if ($self->get_event_count()) { |
161
|
333
|
|
|
|
|
5282
|
$_idle_timer = AnyEvent->idle( cb => \&_loop_resume_timer ); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
443
|
|
|
|
|
9315
|
return 0; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
1; |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
__END__ |