line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBGp::Client::AnyEvent::Listener; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
61415
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
45
|
|
4
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
50
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
939
|
use AnyEvent::Socket qw(tcp_server); |
|
2
|
|
|
|
|
29584
|
|
|
2
|
|
|
|
|
150
|
|
7
|
2
|
|
|
2
|
|
490
|
use DBGp::Client::AnyEvent::Connection; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use Scalar::Util qw(weaken); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
|
|
|
|
|
|
my ($class, %args) = @_; |
12
|
|
|
|
|
|
|
my $self = bless { |
13
|
|
|
|
|
|
|
port => $args{port}, |
14
|
|
|
|
|
|
|
path => $args{path}, |
15
|
|
|
|
|
|
|
mode => $args{mode}, |
16
|
|
|
|
|
|
|
on_connection => $args{on_connection}, |
17
|
|
|
|
|
|
|
tcp_guard => undef, |
18
|
|
|
|
|
|
|
}, $class; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
die "Specify either 'port' or 'path'" unless $self->{port} || $self->{path}; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
return $self; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub listen { |
26
|
|
|
|
|
|
|
my ($self) = @_; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $weak_self = $self; |
29
|
|
|
|
|
|
|
weaken($weak_self); |
30
|
|
|
|
|
|
|
my $cb = sub { $weak_self->_new_connection($_[0]) }; |
31
|
|
|
|
|
|
|
my $prepare = ($self->{path} && defined $self->{mode}) ? sub { |
32
|
|
|
|
|
|
|
chmod $weak_self->{mode}, $weak_self->{path} |
33
|
|
|
|
|
|
|
or die "Unable to change file mode for socket: $!"; |
34
|
|
|
|
|
|
|
} : undef; |
35
|
|
|
|
|
|
|
if ($self->{port}) { |
36
|
|
|
|
|
|
|
$self->{guard} = tcp_server('127.0.0.1', $self->{port}, $cb); |
37
|
|
|
|
|
|
|
} elsif ($self->{path}) { |
38
|
|
|
|
|
|
|
$self->{guard} = tcp_server('unix/', $self->{path}, $cb, $prepare); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _new_connection { |
43
|
|
|
|
|
|
|
my ($self, $fh) = @_; |
44
|
|
|
|
|
|
|
my $connection = DBGp::Client::AnyEvent::Connection->new(socket => $fh); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$self->{on_connection}->($connection); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; |