line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MR::IProto::Server; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 DESCRIPTION |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=cut |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
14658
|
use Mouse; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
12
|
|
10
|
1
|
|
|
1
|
|
418
|
use AnyEvent::Handle; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
11
|
1
|
|
|
1
|
|
11813
|
use AnyEvent::Socket; |
|
1
|
|
|
|
|
46712
|
|
|
1
|
|
|
|
|
166
|
|
12
|
1
|
|
|
1
|
|
13
|
use Scalar::Util qw/weaken/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
57
|
|
13
|
1
|
|
|
1
|
|
777
|
use MR::IProto::Server::Connection; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
575
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
with 'MR::IProto::Role::Debuggable'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has prefix => ( |
18
|
|
|
|
|
|
|
is => 'ro', |
19
|
|
|
|
|
|
|
isa => 'Str', |
20
|
|
|
|
|
|
|
default => sub { ref shift }, |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has host => ( |
24
|
|
|
|
|
|
|
is => 'ro', |
25
|
|
|
|
|
|
|
isa => 'Str', |
26
|
|
|
|
|
|
|
default => '0.0.0.0', |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has port => ( |
30
|
|
|
|
|
|
|
is => 'ro', |
31
|
|
|
|
|
|
|
isa => 'Int', |
32
|
|
|
|
|
|
|
required => 1, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has handler => ( |
36
|
|
|
|
|
|
|
is => 'ro', |
37
|
|
|
|
|
|
|
isa => 'CodeRef', |
38
|
|
|
|
|
|
|
required => 1, |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
has on_accept => ( |
42
|
|
|
|
|
|
|
is => 'ro', |
43
|
|
|
|
|
|
|
isa => 'CodeRef', |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
has on_close => ( |
47
|
|
|
|
|
|
|
is => 'ro', |
48
|
|
|
|
|
|
|
isa => 'CodeRef', |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
has on_error => ( |
52
|
|
|
|
|
|
|
is => 'ro', |
53
|
|
|
|
|
|
|
isa => 'CodeRef', |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
has _guard => ( |
57
|
|
|
|
|
|
|
is => 'ro', |
58
|
|
|
|
|
|
|
lazy_build => 1, |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
has _connections => ( |
62
|
|
|
|
|
|
|
is => 'ro', |
63
|
|
|
|
|
|
|
isa => 'HashRef', |
64
|
|
|
|
|
|
|
default => sub { {} }, |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
has _recv_payload => ( |
68
|
|
|
|
|
|
|
is => 'ro', |
69
|
|
|
|
|
|
|
isa => 'CodeRef', |
70
|
|
|
|
|
|
|
lazy_build => 1, |
71
|
|
|
|
|
|
|
); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub run { |
74
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
75
|
0
|
|
|
|
|
|
$self->_guard; |
76
|
0
|
|
|
|
|
|
return; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _build_debug_cb { |
80
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
81
|
0
|
|
|
|
|
|
my $prefix = $self->prefix; |
82
|
|
|
|
|
|
|
return sub { |
83
|
0
|
|
|
0
|
|
|
my ($msg) = @_; |
84
|
0
|
|
|
|
|
|
chomp $msg; |
85
|
0
|
|
|
|
|
|
warn sprintf "%s: %s\n", $prefix, $msg; |
86
|
0
|
|
|
|
|
|
return; |
87
|
0
|
|
|
|
|
|
}; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub _build__guard { |
91
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
92
|
0
|
|
|
|
|
|
weaken($self); |
93
|
|
|
|
|
|
|
return tcp_server $self->host, $self->port, sub { |
94
|
0
|
|
|
0
|
|
|
my ($fh, $host, $port) = @_; |
95
|
|
|
|
|
|
|
my $connection = MR::IProto::Server::Connection->new( |
96
|
|
|
|
|
|
|
fh => $fh, |
97
|
|
|
|
|
|
|
host => $host, |
98
|
|
|
|
|
|
|
port => $port, |
99
|
|
|
|
|
|
|
handler => $self->handler, |
100
|
|
|
|
|
|
|
on_accept => $self->on_accept, |
101
|
|
|
|
|
|
|
on_close => sub { |
102
|
0
|
|
|
|
|
|
my ($connection) = @_; |
103
|
0
|
|
|
|
|
|
my $key = sprintf "%s:%d", $connection->host, $connection->port; |
104
|
0
|
|
|
|
|
|
delete $self->_connections->{$key}; |
105
|
0
|
0
|
|
|
|
|
$self->on_close->($connection) if $self->on_close; |
106
|
0
|
|
|
|
|
|
return; |
107
|
|
|
|
|
|
|
}, |
108
|
0
|
|
|
|
|
|
on_error => $self->on_error, |
109
|
|
|
|
|
|
|
debug => $self->debug, |
110
|
|
|
|
|
|
|
debug_cb => $self->debug_cb, |
111
|
|
|
|
|
|
|
); |
112
|
0
|
|
|
|
|
|
$self->_connections->{"$host:$port"} = $connection; |
113
|
0
|
|
|
|
|
|
return; |
114
|
0
|
|
|
|
|
|
}; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
1
|
|
|
1
|
|
7
|
no Mouse; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
118
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |