line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
2
|
|
|
|
|
|
|
# Copyright (C) 2005-2015 by Jörn Reder . |
3
|
|
|
|
|
|
|
# All Rights Reserved. See file COPYRIGHT for details. |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# This module is part of Event::RPC, which is free software; you can |
6
|
|
|
|
|
|
|
# redistribute it and/or modify it under the same terms as Perl itself. |
7
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package Event::RPC::Loop::AnyEvent; |
10
|
|
|
|
|
|
|
|
11
|
20
|
|
|
20
|
|
135
|
use base qw( Event::RPC::Loop ); |
|
20
|
|
|
|
|
53
|
|
|
20
|
|
|
|
|
11902
|
|
12
|
|
|
|
|
|
|
|
13
|
20
|
|
|
20
|
|
133
|
use strict; |
|
20
|
|
|
|
|
121
|
|
|
20
|
|
|
|
|
433
|
|
14
|
20
|
|
|
20
|
|
110
|
use utf8; |
|
20
|
|
|
|
|
195
|
|
|
20
|
|
|
|
|
109
|
|
15
|
|
|
|
|
|
|
|
16
|
20
|
|
|
20
|
|
689
|
use AnyEvent; |
|
20
|
|
|
|
|
53
|
|
|
20
|
|
|
|
|
9907
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my %watchers; |
19
|
|
|
|
|
|
|
|
20
|
20
|
|
|
20
|
0
|
329
|
sub get_loop_cv { shift->{loop_cv} } |
21
|
20
|
|
|
20
|
0
|
84
|
sub set_loop_cv { shift->{loop_cv} = $_[1] } |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub add_io_watcher { |
24
|
232
|
|
|
232
|
1
|
505
|
my $self = shift; |
25
|
232
|
|
|
|
|
1000
|
my %par = @_; |
26
|
232
|
|
|
|
|
680
|
my ($fh, $cb, $desc, $poll) = @par{'fh','cb','desc','poll'}; |
27
|
|
|
|
|
|
|
|
28
|
232
|
|
|
|
|
1468
|
my $watcher = AnyEvent->io ( |
29
|
|
|
|
|
|
|
fh => $fh, |
30
|
|
|
|
|
|
|
poll => $poll, |
31
|
|
|
|
|
|
|
cb => $cb, |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
232
|
|
|
|
|
40170
|
$watchers{"$watcher"} = $watcher; |
35
|
|
|
|
|
|
|
|
36
|
232
|
|
|
|
|
858
|
return $watcher; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub del_io_watcher { |
40
|
192
|
|
|
192
|
1
|
313
|
my $self = shift; |
41
|
192
|
|
|
|
|
366
|
my ($watcher) = @_; |
42
|
|
|
|
|
|
|
|
43
|
192
|
|
|
|
|
746
|
delete $watchers{"$watcher"}; |
44
|
|
|
|
|
|
|
|
45
|
192
|
|
|
|
|
491
|
1; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub add_timer { |
49
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
50
|
0
|
|
|
|
|
0
|
my %par = @_; |
51
|
|
|
|
|
|
|
my ($interval, $after, $cb, $desc) = |
52
|
0
|
|
|
|
|
0
|
@par{'interval','after','cb','desc'}; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
0
|
my $timer = AnyEvent->timer ( |
55
|
|
|
|
|
|
|
after => $after, |
56
|
|
|
|
|
|
|
interval => $interval, |
57
|
|
|
|
|
|
|
cb => $cb, |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
0
|
$watchers{"$timer"} = $timer; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
0
|
return $timer; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub del_timer { |
66
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
67
|
0
|
|
|
|
|
0
|
my ($timer) = @_; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
0
|
delete $watchers{"$timer"}; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
0
|
1; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub enter { |
75
|
20
|
|
|
20
|
1
|
56
|
my $self = shift; |
76
|
|
|
|
|
|
|
|
77
|
20
|
|
|
|
|
233
|
my $loop_cv = AnyEvent->condvar; |
78
|
|
|
|
|
|
|
|
79
|
20
|
|
|
|
|
3165
|
$self->set_loop_cv($loop_cv); |
80
|
|
|
|
|
|
|
|
81
|
20
|
|
|
|
|
224
|
$loop_cv->wait; |
82
|
|
|
|
|
|
|
|
83
|
20
|
|
|
|
|
287
|
1; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub leave { |
87
|
20
|
|
|
20
|
1
|
67
|
my $self = shift; |
88
|
|
|
|
|
|
|
|
89
|
20
|
|
|
|
|
93
|
$self->get_loop_cv->send; |
90
|
|
|
|
|
|
|
|
91
|
20
|
|
|
|
|
372
|
1; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |