line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
27
|
|
|
27
|
|
878680
|
use strict; |
|
27
|
|
|
|
|
73
|
|
|
27
|
|
|
|
|
1102
|
|
2
|
27
|
|
|
27
|
|
307
|
use warnings; |
|
27
|
|
|
|
|
67
|
|
|
27
|
|
|
|
|
2451
|
|
3
|
|
|
|
|
|
|
package AnyEvent::SIP; |
4
|
|
|
|
|
|
|
{ |
5
|
|
|
|
|
|
|
$AnyEvent::SIP::VERSION = '0.002'; |
6
|
|
|
|
|
|
|
} |
7
|
|
|
|
|
|
|
# ABSTRACT: Fusing together AnyEvent and Net::SIP |
8
|
|
|
|
|
|
|
|
9
|
27
|
|
|
27
|
|
18853
|
use Net::SIP::Dispatcher::AnyEvent; |
|
27
|
|
|
|
|
102
|
|
|
27
|
|
|
|
|
863
|
|
10
|
27
|
|
|
27
|
|
31972
|
use Net::SIP::Dispatcher::Eventloop; |
|
27
|
|
|
|
|
195448
|
|
|
27
|
|
|
|
|
1841
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub import { |
13
|
27
|
|
|
27
|
|
269
|
my $class = shift; |
14
|
27
|
|
|
|
|
78
|
my @args = @_; |
15
|
|
|
|
|
|
|
|
16
|
27
|
100
|
66
|
|
|
246
|
if ( @args && $args[0] eq 'compat' ) { |
17
|
27
|
|
|
27
|
|
300
|
no warnings qw; |
|
27
|
|
|
|
|
56
|
|
|
27
|
|
|
|
|
3001
|
|
18
|
|
|
|
|
|
|
*Net::SIP::Dispatcher::Eventloop::new = sub { |
19
|
0
|
|
|
0
|
|
0
|
Net::SIP::Dispatcher::AnyEvent->new( _net_sip_compat => 1 ) |
20
|
1
|
|
|
|
|
32
|
}; |
21
|
|
|
|
|
|
|
} else { |
22
|
26
|
|
|
|
|
57
|
my $interval; |
23
|
26
|
50
|
33
|
|
|
177
|
if ( @args && $args[0] eq 'stopvar_interval' ) { |
24
|
0
|
|
|
|
|
0
|
$interval = $args[1]; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
27
|
|
|
27
|
|
143
|
no warnings qw; |
|
27
|
|
|
|
|
57
|
|
|
27
|
|
|
|
|
2913
|
|
28
|
|
|
|
|
|
|
*Net::SIP::Dispatcher::Eventloop::new = sub { |
29
|
19
|
|
|
19
|
|
297828
|
Net::SIP::Dispatcher::AnyEvent->new( _ae_interval => $interval ) |
30
|
26
|
|
|
|
|
956
|
}; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
1; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=pod |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 NAME |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
AnyEvent::SIP - Fusing together AnyEvent and Net::SIP |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 VERSION |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
version 0.002 |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 SYNOPSIS |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# regular Net::SIP syntax |
51
|
|
|
|
|
|
|
use AnyEvent::SIP; |
52
|
|
|
|
|
|
|
use Net::SIP::Simple; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $stopvar; |
55
|
|
|
|
|
|
|
my $ua = Net::SIP::Simple->new(...); |
56
|
|
|
|
|
|
|
my $call = $uac->invite( |
57
|
|
|
|
|
|
|
'you.uas@example.com', |
58
|
|
|
|
|
|
|
cb_final => sub { $stopvar++ }, |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# wait for $stopvar, 5 second timeout |
62
|
|
|
|
|
|
|
$ua->loop( 5, \$stopvar ); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# AnyEvent-style |
65
|
|
|
|
|
|
|
use AnyEvent::SIP; |
66
|
|
|
|
|
|
|
use Net::SIP::Simple; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $cv = AE::cv; |
69
|
|
|
|
|
|
|
my $ua = Net::SIP::Simple->new(...); |
70
|
|
|
|
|
|
|
my $call = $uac->invite( |
71
|
|
|
|
|
|
|
'you.uas@example.com', |
72
|
|
|
|
|
|
|
cb_final => sub { $cv->send }, |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
$cv->recv; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# compat-mode |
78
|
|
|
|
|
|
|
use AnyEvent::SIP 'compat'; |
79
|
|
|
|
|
|
|
... |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 DESCRIPTION |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
This module allows you to use L as the event loop (and thus any |
84
|
|
|
|
|
|
|
other supported event loop) for L. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
L allows you to define the event loop. You can either define |
87
|
|
|
|
|
|
|
it using L manually or you can simply use |
88
|
|
|
|
|
|
|
L which will automatically set it for you. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# doing it automatically and globally |
91
|
|
|
|
|
|
|
use AnyEvent::SIP; |
92
|
|
|
|
|
|
|
use Net::SIP::Simple; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
my $cv = AE::cv; |
95
|
|
|
|
|
|
|
my $ua = Net::SIP::Simple->new(...); |
96
|
|
|
|
|
|
|
$ua->register( cb_final => sub { $cv->send } ); |
97
|
|
|
|
|
|
|
$cv->recv; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# defining it for a specific object |
100
|
|
|
|
|
|
|
use Net::SIP::Simple; |
101
|
|
|
|
|
|
|
use Net::SIP::Dispatcher::AnyEvent; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $cv = AE::cv; |
104
|
|
|
|
|
|
|
my $ua = Net::SIP::Simple->( |
105
|
|
|
|
|
|
|
... |
106
|
|
|
|
|
|
|
loop => Net::SIP::Dispatcher::AnyEvent->new, |
107
|
|
|
|
|
|
|
); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
$ua->register; |
110
|
|
|
|
|
|
|
$cv->recv; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
You can also call L's C method in order to keep it as close as |
113
|
|
|
|
|
|
|
possible to the original syntax. This will internally use L, whether |
114
|
|
|
|
|
|
|
you're using L globally or L |
115
|
|
|
|
|
|
|
locally. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
use AnyEvent::SIP; |
118
|
|
|
|
|
|
|
use Net::SIP::Simple; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
my $stopvar; |
121
|
|
|
|
|
|
|
my $ua = Net::SIP::Simple->new(...); |
122
|
|
|
|
|
|
|
$ua->register( cb_final => sub { $stopvar++ } ); |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# call Net::SIP's event loop runner, |
125
|
|
|
|
|
|
|
# which calls AnyEvent's instead |
126
|
|
|
|
|
|
|
$ua->loop( 1, \$stopvar ); |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 COMPATIBILITY |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
L requires dispatchers (event loops) to check their stopvars |
131
|
|
|
|
|
|
|
(condition variables) every single iteration of the loop. In my opinion, it's |
132
|
|
|
|
|
|
|
a wasteful and heavy operation. When it comes to loops like L, they run |
133
|
|
|
|
|
|
|
a B of cycles, and it's not very effecient and causes heavy load. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
To avoid that, the default mode for L is to set up a timer |
136
|
|
|
|
|
|
|
to check the condition variables. Default interval is: B<0.2> seconds. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
To configure this, you can set up the interval on import: |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
use AnyEvent::SIP stopvar_interval => 0.1; |
141
|
|
|
|
|
|
|
... |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
If you want to keep AnyEvent::SIP completely compatible with the L |
144
|
|
|
|
|
|
|
requirement (which fixes at least one bugfix test I haven't found out why yet), |
145
|
|
|
|
|
|
|
you can add the compat option on import; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
use AnyEvent::SIP 'compat'; |
148
|
|
|
|
|
|
|
... |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
I can't promise not to change any of this. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 AUTHOR |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Sawyer X |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
This software is copyright (c) 2013 by Sawyer X. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
161
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=cut |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
__END__ |